>>72,75 false_expr would also be evaluated if true_expr evaluated as false. But it works for stuff like print (debug && "Couldn't desecrate the mangina on line 45!" || "Something bad happened.")
>>82
Perl has a lovely way of solving that. You could also just use nesting.
As much as duplication of facilities is a tiresome path (see Perl), I really think S-expressions should show up in languages that don't strictly need them. The convenience of the ternary op could be unified with regular if/else blocks if done in S-expression form.
I wanted to do something like foo = 4 (bar ? + : -) 2; and it doesn't work. Is there any clever way of making it work without putting the whole addition and subtraction inside the operator?
>>92 foo = 2 + (!bar) << 2;
I like it how you posted a solution that applies only to the particular case of addition/subtraction even though they were an obvious example.
>>94
Whatever you meant when you said that, it's easy to simplify whatever similar mathematical expression into that form.
Name:
Anonymous2010-07-09 11:46
opium dreams
Name:
Anonymous2010-07-09 11:51
people who `optimize" their programs into a nests of ternary expressions, don't know 'bout CPU Branch Predictors and penalty for not guessing the correct jump.
In fact most optimized program is one with least branches(jumps).