<div dir="ltr"><div>I didn&#39;t actually try </div><div>```</div><div><div style="font-size:13px">if x? {</div><div style="font-size:13px"><span style="white-space:pre-wrap">        </span>foo(x) // x type narrowed after binding.</div><div style="font-size:13px">}</div></div><div style="font-size:13px">```</div><div style="font-size:13px"><br></div><div style="font-size:13px">in a swift file and I should have.</div><div style="font-size:13px"><br></div><div><br></div>To misquote a movie<div><i style="font-size:13px">That code, you keep using that code. I do not think it does what you think it does.</i><br></div><div><i style="font-size:13px"><br></i></div>I *do* recall discussion of this syntax and it might have been in an earlier version, but it does not work now. What I receive is  `error: optional type &#39;_?&#39; cannot be used as a boolean; test for &#39;!= nil&#39; instead`. I agree with this because that question mark was not, in my opinion, sigil enough for the action.<div><div class="" style="font-size:13px"></div></div><div><br></div><div><br></div></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">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</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">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 class="h5"><div><br></div><div><br><div><blockquote type="cite"><div>On Feb 1, 2016, at 11:35 AM, Howard Lovatt via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; 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 &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; 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">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 &lt;<a>swift-evolution@swift.org</a>&gt; 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">&lt;<a>swift-evolution@swift.org</a>&gt;</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 &quot;<span style="font-family:Palatino-Roman">If you all are serious about this, I think you should start a new thread about it.&quot; </span><div>I think it&#39;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&#39;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&#39;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 &quot;if bind foo&quot; to my original &quot;if bind foo = foo&quot;:</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&#39;s approach offers my original &quot;bind&quot; 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) =&gt; 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&#39;m throwing these both out there. I have nothing to really say about Tino&#39;s but I do think my and Jacob&#39;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 href="mailto:swift-evolution@swift.org" target="_blank">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 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>