[swift-evolution] ternary operator ?: suggestion
Jordan Rose
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"
> vs.
> "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.)
Jordan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151214/d2256797/attachment.html>
More information about the swift-evolution
mailing list