[swift-evolution] ternary operator ?: suggestion
Craig Cruden
ccruden at novafore.com
Wed Jan 6 21:39:48 CST 2016
multiary is not a natural and easy expression to pronounce.
ternary was likely used originally because they could not think of something better - but at least it is easy on the tongue…. [composed of 3 parts]
regardless of syntax - maybe just call it a “match expression”.
> On 2016-01-07, at 10:06:46, Charles Constant via swift-evolution <swift-evolution at swift.org> wrote:
>
> > 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"
>
>
>
>
>
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160107/a1c0c338/attachment.html>
More information about the swift-evolution
mailing list