[swift-evolution] Fwd: Propagating Optionals

Kevin Nattinger swift at nattinger.net
Fri Oct 7 17:14:56 CDT 2016


> On Oct 7, 2016, at 2:56 PM, Trans via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Just discovered that none of my replies made it to the mailing list.
> Doesn't it bug others that the default reply is to the author and not
> the list?
> 
> 
> ---------- Forwarded message ----------
> From: Trans <transfire at gmail.com>
> Date: Sun, Sep 25, 2016 at 9:36 PM
> Subject: Re: [swift-evolution] Propagating Optionals
> To: William Sumner <prestonsumner at me.com>
> 
> 
> On Sun, Sep 25, 2016 at 7:26 PM, William Sumner <prestonsumner at me.com> wrote:
>> 
>> You can accomplish this using parenthesis:
>> 
>> let roomCount = (john.residence ?? homelessShelter).numberOfRooms
> 
> Yea. Don't know why that escaped me. Though it does start to look long
> in the tooth if there is more than one.
> 
>    let x = ((foo.bar ?? dbar).baz ?? dbaz).zee
> 
> vs
> 
>    let x = foo.bar:dbar.baz:dbaz.zee

I’m not sure what I’d expect a raw `:` operator to do, but whatever it is I’d expect it to have a lower priority than `.`, making your statement equal to

    let x = (foo.bar) : (dbar.baz) : (dbaz.zee)

Member access (`.`) is a *very* high precedence operator in every language I can think of, and I think it would be quite confusing to slip something in above it.

> 
> But then again maybe that is too concise.
> 
> 
> -- 
> People with courage and character always seem sinister to the rest.
> --Hermann Hesse
> 
> Trans <transfire at gmail.com>
> 7r4n5.com      http://7r4n5.com
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution



More information about the swift-evolution mailing list