<div dir="ltr">I'm -1 as stated, I don't think the proposed change adds any clarity, if anything it adds more things to learn.<div><br></div><div>I think you can achieve some of your goals with a linter. You need to consider how this works with pattern matching. It would remove the ability to mutate the value type in a switch without a reassignment.<br><div><div><br></div><div>I'm closer to liking it if it removes nothing from the language and adds something like this:</div><div><br></div><div>var x: Int?</div><div>let y: Int?</div><div>if bind x, y where x == y {</div><div> x = 4 // changes the x outside this scope</div><div> y = 5 // compile time error</div><div> x = nil // compile time error</div><div>}</div><div><br></div><div>I think that makes bind make more sense, and less surprising. However it doesn't clarify anything about it no longer being optional.</div><div><br></div><div>It would be nice if the following worked, although I it has its own issues with surprises:</div><div><br></div><div>let x: Int? = 123</div><div>if x != nil {</div><div> ... // x is non-optional here</div><div>}</div><div>assert(x != nil)</div><div>// x is non-optional here<br></div><div><br></div><div>var y: Int? = 456<br></div><div>while y != nil {</div><div> // y is non-optional here</div><div>}</div><div>// y is optional here</div><div><br></div><div><div>On Tuesday, 2 February 2016, T.J. Usiyan via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">I don't think that the keyword is silly but this is a good point. I forgot that this application of the `?` postfix exists.</div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Feb 1, 2016 at 2:56 PM, Tyler Cloutier via swift-evolution <span dir="ltr"><<a>swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word">The bind or exists keywords seem sort of silly to me. There is already syntax for binding optionals:<div><br></div><div>if x? {</div><div><span style="white-space:pre-wrap">        </span>foo(x) // x type narrowed after binding.</div><div>}<br><div><br></div><div>Tyler</div><div><div><div><br></div><div><br><div><blockquote type="cite"><div>On Feb 1, 2016, at 11:35 AM, Howard Lovatt via swift-evolution <<a>swift-evolution@swift.org</a>> wrote:</div><br><div>I like this proposal. I also think that either bind or exists could be the keyword. I would suggest that both forms of syntax should be allowed, e.g.:<div><br></div><div> if bind x { /* x is non-nil, unwrapped, and hides original x inside if statement <span></span>*/ }</div><div> if bind x = object.property <font size="2"><span style="background-color:rgba(255,255,255,0)">{ /* x is non-nil and unwrapped */ }</span></font><br><br>On Tuesday, 2 February 2016, Dave via swift-evolution <<a>swift-evolution@swift.org</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word">I <i>think</i> it’d be _<div><br></div><div>You could use it to test if the return value is non-nil, but you’d have to revert to “if let x = …” to actually use the results.</div><div><br></div><div>I think.</div><div><br><div>
- Dave Sweeris
</div>
<br><div><blockquote type="cite"><div>On Feb 1, 2016, at 11:22, T.J. Usiyan via swift-evolution <<a>swift-evolution@swift.org</a>> wrote:</div><br><div><div dir="ltr"><div>This is interesting. What name is created by </div><div><br></div><div><div style="font-size:13px"><font face="Menlo"> if bind foo.somethingReturningAnOptional {</font></div><div style="font-size:13px"><font face="Menlo"> // ???</font></div><div style="font-size:13px"><font face="Menlo"> }</font></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Feb 1, 2016 at 2:18 PM, Erica Sadun via swift-evolution <span dir="ltr"><<a>swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word">Joe says "<span style="font-family:Palatino-Roman">If you all are serious about this, I think you should start a new thread about it." </span><div>I think it's worth a serious discussion just so it can be evaluated and either adopted or discarded</div><div>and dropped forever. Here goes.</div><div><br></div><div>INTRO</div><div><br><div>The <font face="Menlo">if let x = x {...}</font> and <font face="Menlo">guard let x = x else {...}</font> constructs do something with <font face="Menlo">let</font> (and <font face="Menlo">var</font>) that's </div><div>fundamentally different from <font face="Menlo">let</font> (and <font face="Menlo">var</font>) elsewhere in the language. The same keywords are used to conditionally unwrap</div><div>and bind an item, not just shadow that item's current value.</div><div><br></div><div>Introducing a new <font face="Menlo">bind</font> keyword to indicate unwrapping and binding would disambiguate these uses.</div><div><br></div><div>DETAIL DESIGN:</div><div><br></div><div>Jacob Bandes-Storch offers two common use-cases. I prefer his "if bind foo" to my original "if bind foo = foo":</div><div><br></div><div><div><font face="Menlo"> if bind foo {</font></div><div><font face="Menlo"> // foo is non-optional in here</font></div><div><font face="Menlo"> }</font></div><div><font face="Menlo"><br></font></div><div><font face="Menlo"> somethingAsync { [weak self] in</font></div><div><font face="Menlo"> guard bind self else { return }</font></div><div><font face="Menlo"> // ...</font></div><div><font face="Menlo"> }</font></div></div><div><br></div></div><div>JBS's approach offers my original "bind" keyword to unwrap and shadow bind, but also provides a way to </div><div>strongly bind a weak reference to self, which (presumably) would allow self semantics in the remaining</div><div>lifetime of that scope.</div><div><br></div><div>ALTERNATIVE PROPOSALS:</div><div><br></div><div>Tino Heth proposes a second use-case one with different semantics. This case, it seems to make an</div><div>alias rather than using binding for shadowing:</div><div><br></div><div><font face="Menlo">bind x = a.property.with.a.long.path<br>print x // 42<br>print(a.property.with.a.long.path == 42) => true</font></div><div><span style="font-family:Palatino-Roman"><br></span></div><div><span style="font-family:Palatino-Roman">presumably this means:</span></div><div><span style="font-family:Palatino-Roman"><br></span></div><div><font face="Menlo">x += 1</font></div><div><font face="Menlo">print(a.property.with.a.long.path) // 43</font></div><div><font face="Palatino-Roman"><br></font></div><div><font face="Palatino-Roman">DISCUSSION</font></div><div><font face="Palatino-Roman"><br></font></div><div><font face="Palatino-Roman">I'm throwing these both out there. I have nothing to really say about Tino's but I do think my and Jacob's </font></div><div><font face="Palatino-Roman">proposal has the advantages of:</font></div><div><font face="Palatino-Roman"><br></font></div><div><font face="Palatino-Roman">* Simplifying an mildly complex and potentially misleading statement </font></div><div><font face="Palatino-Roman">* Creating a deliberate and controlled rather than accidental shadowing style</font></div><div><font face="Palatino-Roman"><br></font></div><div><font face="Palatino-Roman">Have at it.</font></div><span><font color="#888888"><div><font face="Palatino-Roman"><br></font></div><div><font face="Palatino-Roman">-- Erica</font></div><div><font face="Palatino-Roman"><br></font></div><div><font face="Palatino-Roman"><br></font></div></font></span></div><br>_______________________________________________<br>
swift-evolution mailing list<br>
<a>swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div>
_______________________________________________<br>swift-evolution mailing list<br><a>swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div></blockquote></div><br></div></div></blockquote></div><br><br>-- <br> -- Howard.<br><br>
_______________________________________________<br>swift-evolution mailing list<br><a>swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div></blockquote></div><br></div></div></div></div></div><br>_______________________________________________<br>
swift-evolution mailing list<br>
<a>swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div>
</blockquote></div></div>
</div></div></div>