There is a language, Nice (related to Java), that does:<div><br></div><div>    if x != nil {</div><div>        // x is unwrapped</div><div>    }</div><div><br></div><div>As Andrew has already suggested as a possibility. However I am not sure that it is a great idea because why should this particular if statement have &#39;magic&#39;?</div><div><br></div><div>How about:</div><div><br></div><div>    <font size="2"><span style="background-color:rgba(255,255,255,0)"> ifsome x { // Equivalent to current `if let x = x`, note `ifsome` is one word</span></font><div><font size="2"><span style="background-color:rgba(255,255,255,0)">        // x is unwrapped</span></font></div><div><font size="2"><span style="background-color:rgba(255,255,255,0)">    }</span></font></div><div><font size="2"><span style="background-color:rgba(255,255,255,0)"><br></span></font></div><div><font size="2"><span style="background-color:rgba(255,255,255,0)">This doesn&#39;t use `bind` which has some baggage, it doesn&#39;t use `var` or `let` which have other meanings, `ifsome` is an unusual word and hence unlikely to be useful as a name, and it is clear it is not a normal `if` statement.</span></font></div><div><font size="2"><span style="background-color:rgba(255,255,255,0)"><br></span></font></div><div><font size="2"><span style="background-color:rgba(255,255,255,0)">Don&#39;t change `case` clauses, they are not confusing, they do introduce a new variable and hence `let` and `var` are appropriate. </span></font></div><br>On Tuesday, 2 February 2016, Andrew Bennett via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">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 dir="ltr">I&#39;m -1 as stated, I don&#39;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&#39;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&#39;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 &lt;<a href="javascript:_e(%7B%7D,&#39;cvml&#39;,&#39;swift-evolution@swift.org&#39;);" target="_blank">swift-evolution@swift.org</a>&gt; 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&#39;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">&lt;<a>swift-evolution@swift.org</a>&gt;</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 &lt;<a>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>swift-evolution@swift.org</a>&gt; 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 &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: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 &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>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>
</blockquote></div><br><br>-- <br>  -- Howard.<br><br>