<div dir="ltr">I think it's also worth mentioning Ceylon's <a href="http://ceylon-lang.org/documentation/1.2/introduction/#typesafe_null_and_flow_sensitive_typing">flow-sensitive typing</a> features, pointed out by Thorsten Seitz:<div><br></div><div><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">This is called flow typing in Ceylon and they are using "exists" for that case but testing for conformance with "is" works just the same way there. The latter is of importance because the common use of union types in Ceylon.<br>if exists foo {<br> // foo is non-optional here<br>}<br>if foo is String {<br> // foo is of type String here<br>}</blockquote></div><div class="gmail_extra"><div><div class="gmail_signature"><div dir="ltr"><div><br></div><div>Seems like a neat option to me.</div></div></div></div>
<br><div class="gmail_quote">On Mon, Feb 1, 2016 at 11:18 AM, Erica Sadun via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc 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 class="HOEnZb"><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 href="mailto:swift-evolution@swift.org">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></div>