[swift-evolution] ternary operator ?: suggestion

Charles Constant charles at charlesism.com
Wed Jan 6 21:06:46 CST 2016


> I see what you are trying to do, because of the colon being both used for
switch cases and
> separators for the ternary and so there needs to be a new character for
each case.
> I am not sure that putting colons between each case is really necessary
though.

Most of us (including you and I) like a form that starts with " let val =
condition ? " like the existing ternary. Let's say a proposal like that
gets accepted... I really believe "colons as separators" is the best idea
in the case. Otherwise, it gets pretty confusing.. we'll have the existing
ternary where a colon does one thing, and our new "extra ternary" where it
does something else.

This is why I like colons (this won't make sense unless your email has rich
text to show the colors):

* let val = color ? *

*.Red !**  0xFF0000 : *

*.Green !**  0x00FF00 : *

*_ !**  0xFFFFFF*

... no syntax here different from the existing except the addition "
*.Red !* ". As for the exclamation... Swift already uses an exclamation for
a billion other things, which is unfortunate. But the same can be said of
"?" and that's already used in a "switch" without causing confusion.

> To point 1: I agree it needs a new name, I came up with the “demux
expression”

> but maybe there is a better name.

Has anyone suggested "multiary expression" yet? Seems in keeping with
"ternary"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160106/221c6c48/attachment.html>


More information about the swift-evolution mailing list