[swift-evolution] ternary operator ?: suggestion

Charles Constant charles at charlesism.com
Wed Jan 6 22:11:31 CST 2016


> multiary is not a natural and easy expression to pronounce.

I'd be fine with "match expression". Also fine with "multary" (no "i"),
which is apparently a common alternative to "multiary."

If we use the "colon as separator" version of this proposal, which uses the
existing syntax for a ternary, I'd prefer we just called it a "ternary" or
a "[something] ternary". Granted with 3+ terms, it's a misnomer, but it's
not hard to imagine someone saying "Oh, when you write a Ternary in Swift,
you can add conditions to it." I'm quite sure "ternary" is the first thing
you would Google, if you came across the kind of expression we're proposing.



On Wed, Jan 6, 2016 at 7:39 PM, Craig Cruden <ccruden at novafore.com> wrote:

> 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/20160106/96647f68/attachment.html>


More information about the swift-evolution mailing list