I missed it too. But I think it's no great loss, especially since we
got the extended switch() statement instead - I think my savings in
typing there more than outweighs the loss on the ternary operator.
you can always do this instead, it's kind of the same.
stuff := func()int{if 5>6 {return 8} return 5}();
(That's not to say I don't agree that ternary operations aren't mentally useful, but not at the expense of readable results.)
This lacks a vital component of the conditional operator (often called
the ternary operator): only a or b will be evaluated, never both.
func T(exp bool, a interface{}, b interface{}) (interface{}) {
if exp { return a } return b }
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
It does not work. Unlike an if-expression, both of the conditional parts. Are evaluated at the call. (also the result will have to be converted back to the right type.
Chris onna bus.
--
1. GCC allows an expression in braces to have a value; the value of the final statement. ("x = {b += 20; b--}" will assign b+19 to x. ("x = {c += 20; c--; 42}" will assign 42 to x.2. Algol68/Pascal/Modula/etc. all appreciate "if" more generally than most of the languages that followed them.Synthesizing these two ideas gives...(drumroll)...x := if exp {a} else {b}
Just way too easy to abuse the ternary operator...