[swift-evolution] Proposal: Optional Binding Shorthand Syntax

Tyler Mandry tmandry at gmail.com
Sun Dec 6 16:48:10 CST 2015


True, I meant why was the `?` taken out of the syntax. I suppose it can
feel redundant to have `if x? = try? foo()` or similar, in the cases you
mentioned. That said, in the common case of unwrapping a variable of
optional type (`let foo: Int?`) which is not written with a `?`, it can add
extra clarity.

On Sun, Dec 6, 2015 at 4:42 PM, Chris Lattner <clattner at apple.com> wrote:

>
> > On Dec 6, 2015, at 1:38 PM, Tyler Mandry via swift-evolution <
> swift-evolution at swift.org> wrote:
> >
> > What isn't clear to me from Chris's or John's comments is why the `if
> let x? = foo` syntax was taken away. Was it for backward-compatibility?
>
> FWIW, that syntax hasn’t been taken away, it just means something
> different now.
>
>         if let x = foo() {
>
> captures is privileged syntax for testing an optional and binding to the
> thing inside of it.  The patch I linked to moved away from this, but at
> great cost: it uglified lots of common code.  Swift privileges optional in
> a number of ways (e.g. it is the result of as?, try?, etc) and the standard
> library uses it pervasively as well.  Optimizing for that common case makes
> sense.
>
> -Chris
>
>
>


-- 
Tyler Mandry
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151206/efe3eb96/attachment.html>


More information about the swift-evolution mailing list