News for hackers. Stuff that matters.
Re:The Idea of Lisp by coderzach on Friday December 16, 2016 @10:16AM (#13193788)
I see two issues with the ternary operator. One, the syntax is much less readable, and two, the consequent and alternate are both single expressions, so you can't do something like:

x = if(something) { a = foo(); baz(a); } else { b = bar(); baz(b); }

Re:The Idea of Lisp by kazinator on Friday December 16, 2016 @01:50PM (#13195675)
It should work in GNU C:

  x = (something) ? ({ a = foo(); baz(a) }) : ({ b = bar(); baz(b); });
However, since all your forms are actually expression statements, we can happily just use the ISO C comma operator:

  x = (something) ? (a = foo(), baz(a)) : (b = bar(); baz(b));
If C provided operators for iteration, selection and for binding some variables over a scope (that scope consisting of an expression), everything would be cool. E.g. fantasy while loop:

  x = (< y 0) ?? y++ : y;   // evaluate y++ while (< y 0), then yield y.
Variable binding:

  x = let (int x = 3, double y = 3.0) : (x++, x*y);
The problem is that some things can only be done with statements.

The ternary operator is not actually lacking anything; with the comma operator, multiple expressions can be evaluated. What's lacking is the vocabulary of what those expressions can do.

Re:The Idea of Lisp by heywire on Friday December 16, 2016 @11:12AM (#13194205)
I've always read ternary statements to myself as a question.

  some_condition ? this : that
some_condition? then this, otherwise that

Typing this, I realize how hard it is to explain without speaking it :)

Re:The Idea of Lisp by lawpoop on Friday December 16, 2016 @12:57PM (#13195229)
Is the color red? If so, this; otherwise, that.

It's a little tricky, because in the above, the `if` keyword appears after the question mark.

Is the color red? Yes-- this: no-- that.

Trying to make a parsimonious English sentence while maintaining the syntax elements : P

Re:The Idea of Lisp by kbutler on Friday December 16, 2016 @02:58PM (#13196234)
> some_condition ? this : that

Just read it as:

  IF some_condition THEN this ELSE that
Re:The Idea of Lisp by junke on Friday December 16, 2016 @11:32AM (#13194402)
You compute baz in both branches, you can refactor.

    x = baz(if (something) foo() else bar())
Re:The Idea of Lisp by tacostakohashi on Friday December 16, 2016 @12:10PM (#13194763)
If you insist on the assignments:

x = something ? ((a=foo()), baz(a)) : ((b = bar()), baz(b));

Otherwise:

x = something ? baz(foo()) : baz(bar());

Re:The Idea of Lisp by vertex-four on Friday December 16, 2016 @01:27PM (#13195468)
a and b have to be defined before the statement containing the terniary expression here. And the point is that you can embed arbitrary multi-statement logic in your if expressions in Rust in the same way you'd do it anywhere else.