[swift-evolution] ternary operator ?: suggestion
jordan_rose at apple.com
Mon Dec 14 17:38:33 CST 2015
> On Dec 13, 2015, at 8:11, Jakob Egger via swift-evolution <swift-evolution at swift.org> wrote:
> But there is one good side to this proposal: it nests more naturally than the ternary operator:
> "if cond then expr1 else if cond2 then expr2 else expr3"
> "cond ? expr1 : (cond2 ? expr2 : expr3)
Without commenting on anything else in this thread, ?: nests properly (right-associative-ly) in every language other than PHP <http://www.phpsadness.com/sad/30>. Dropping the parens there is equivalent.
(That said, if I hadn't known that already it wouldn't have been something I could infer from the syntax. I'd have to assume the author knew what they were doing. And I'm the sort who will parenthesize && expressions within || expressions, even though it's not strictly necessary.)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution