<div dir="ltr"><span><div>I would like to add on to your idea and propose mixing in David&#39;s suggestion:<br></div><div><div><div><br></div><div><pre style="overflow:auto;font-family:Consolas,&#39;Liberation Mono&#39;,Menlo,Courier,monospace;margin-top:0px;margin-bottom:0px;line-height:1.45;padding:16px;background-color:rgb(247,247,247);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-wrap:normal;word-break:normal;color:rgb(51,51,51)"><span style="color:rgb(167,29,93)">if</span> <span style="color:rgb(167,29,93)">let</span> thing?, otherThing?, moreThings? <span style="color:rgb(167,29,93)">where</span> thing <span style="color:rgb(167,29,93)">&gt;</span> <span style="color:rgb(0,134,179)">0</span> { }</pre></div><div><br></div></div></div></span><div>I think this makes it clearer that the variables are optionals, which could lead newcomers to infer that they are being unwrapped. Just my two cents.</div><div><br></div><div>Also,<div><div><br></div><div><div><blockquote type="cite" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">I agree with David in that the existing syntax is already at the point where your statement is also true.</blockquote></div></div><div><br></div><div>is fair, but it is made significantly clearer that there is some sort of assignment going on in the existing implementation (because of the equal sign).</div></div></div><div><br></div><div><span><div id="bloop_customfont" style="color:rgb(0,0,0);font-family:Helvetica,Arial;margin:0px"><span style="font-family:helvetica,arial">— </span></div><div id="bloop_sign_1449203852020918016" class="bloop_sign" style="color:rgb(0,0,0);font-family:Helvetica,Arial"><div style="font-family:helvetica,arial">Dan Appel</div></div></span></div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, Dec 3, 2015 at 8:57 PM Zef Houssney &lt;<a href="mailto:zefmail@gmail.com">zefmail@gmail.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Interesting thoughts! And thanks for the consideration Chris. Just a couple more thoughts and I’ll drop this :)<div><br></div><div>Chris, I love the way you put this:</div><div><br></div><div></div></div><div style="word-wrap:break-word"><div><blockquote type="cite"><div><div><div><div><div><span style="display:inline!important">Since code is read more often than it is written, the real goal behind Swift is to let you write “more readable code” by eliminating boilerplate and other noise.</span></div></div></div></div></div></blockquote></div></div><div style="word-wrap:break-word"><div><div><div><br></div><div>In my view, this proposal is aligned with that goal and it’s as much about readability as anything. I find this first example so much more readable at a glance, and I consider the duplicate names and equals sign to be in the boilerplate/noise category:</div><div><br></div><div><pre style="overflow:auto;font-family:Consolas,&#39;Liberation Mono&#39;,Menlo,Courier,monospace;margin-top:0px;margin-bottom:0px;line-height:1.45;padding:16px;background-color:rgb(247,247,247);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-wrap:normal;word-break:normal;color:rgb(51,51,51);font-size:13px"><span style="color:rgb(167,29,93)">if</span> <span style="color:rgb(167,29,93)">let</span> thing, otherThing, moreThings <span style="color:rgb(167,29,93)">where</span> thing <span style="color:rgb(167,29,93)">&gt;</span> <span style="color:rgb(0,134,179)">0</span> { }</pre><pre style="overflow:auto;font-family:Consolas,&#39;Liberation Mono&#39;,Menlo,Courier,monospace;margin-top:0px;margin-bottom:0px;line-height:1.45;padding:16px;background-color:rgb(247,247,247);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-wrap:normal;word-break:normal;color:rgb(51,51,51);font-size:13px"><span style="line-height:1.45;color:rgb(167,29,93)">if</span><span style="line-height:1.45"> </span><span style="line-height:1.45;color:rgb(167,29,93)">let</span><span style="line-height:1.45"> thing </span><span style="line-height:1.45;color:rgb(167,29,93)">=</span><span style="line-height:1.45"> thing, otherThing </span><span style="line-height:1.45;color:rgb(167,29,93)">=</span><span style="line-height:1.45"> otherThing, moreThings </span><span style="line-height:1.45;color:rgb(167,29,93)">=</span><span style="line-height:1.45"> moreThings </span><span style="line-height:1.45;color:rgb(167,29,93)">where</span><span style="line-height:1.45"> thing </span><span style="line-height:1.45;color:rgb(167,29,93)">&gt;</span><span style="line-height:1.45"> </span><span style="line-height:1.45;color:rgb(0,134,179)">0</span><span style="line-height:1.45"> { }</span></pre></div><div><br></div><div><br></div><div>Kevin, in regard to this:</div><div><br></div><div><blockquote type="cite">Furthermore, to anyone not already familiar with the proposed rule, `if let foo {` is meaningless</blockquote></div><div><br></div><div>I agree with David in that the existing syntax is already at the point where your statement is also true. There is nothing in the current syntax that indicates that you are unwrapping the optional. It’s only through learning or familiarity with other languages that one understands it. The = indicates assignment, but the unwrapping is learned and specific to that context. The jump to this seems super easy to grok.</div><div><br></div><div>Also my point isn’t that it’s doing the same thing technically, but that it’s a similar concept — assigning to a constant with the value derived implicitly by the context instead of directly through ‘=‘.</div><div><br></div><div>The idea of another keyword like “when” also seems plausible to me, though it’s a much more drastic change.</div></div></div></div><div style="word-wrap:break-word"><div><div><div><br></div><div><br></div><div><br></div><div><br><div><blockquote type="cite"><div>On Dec 3, 2015, at 8:13 PM, Sean Heber &lt;<a href="mailto:sean@fifthace.com" target="_blank">sean@fifthace.com</a>&gt; wrote:</div><br><div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">What about lifting the whole concept out of &quot;if&quot; or &quot;guard&quot; and making a new construct that directly communicates the intent?</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">For example:</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">when foo { ... }</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">Which could be combined with &quot;where&quot; to generate an if-like construct:</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">when foo where foo.isSomething { ... }</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">Inside the code block, you can access foo directly and it isn&#39;t shadowed - so if it was a var, it is mutable, etc.</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">l8r</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">Sean</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br>On Dec 3, 2015, at 8:25 PM, David Waite &lt;<a href="mailto:david@alkaline-solutions.com" target="_blank">david@alkaline-solutions.com</a>&gt; wrote:<br><br></div><blockquote type="cite" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div>I might argue that if let is already an odd case; people often read it equivalent to &quot;if (let x=x)”, but “let x=x” has completely different behavior outside the context of an if let statement (I in fact had to try it before I realized it does, in fact, work). Obviously, &#39;let x=x’ on its own could not have the same behavior.<div><br><div>In that spirit, I propose an alternative feature:</div><div><br></div><div>if foo? { … }</div><div><br></div><div>where the variable is not shadowed by a copy - instead, inside the block it behaves as an implicit unwrapped optional, including keeping any mutability.</div><div><br></div><div>so for example:</div><div><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(169,169,169)"> </span>func foo(x:Int?) { </div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(169,169,169)"> </span>    if var x = x { // var so it can be assigned</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(169,169,169)"> </span>        x++ </div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(169,169,169)"> </span>    } </div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(169,169,169)"> </span>    print(x) </div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(169,169,169)"> <span>} </span></div></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(169,169,169)"><span><br></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(169,169,169)"><span>foo(1) // =&gt; 1, updating the aliased x does not do anything</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(169,169,169)"><span><br></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(169,169,169)"><span># working code in Swift 1.2</span></div><div style="margin:0px;line-height:normal"><font face="Menlo"><span style="font-size:11px"> func bar(x:Int?) { <br>     var y=x <br>     if let x=x { <br>         y=x+1 <br>     } <br>     print(y) <br> } <br></span></font></div><div style="margin:0px;line-height:normal"><div>bar(1) # =&gt; Optional(2)</div><div><br></div></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(169,169,169)"><span># proposed</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(169,169,169)"><div style="font-family:Helvetica;font-size:12px"><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">func proposed(x:Int?) {</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">     var y = x // since swift 3 won&#39;t have var function arguments</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(169,169,169)"> </span>    if y? { // var so it can be assigned</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(169,169,169)"> </span>        y++ </div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(169,169,169)"> </span>    } </div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(169,169,169)"> </span>    print(y) </div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(169,169,169)"> <span>} </span></div><div><span><br></span></div><div><span>proposed(1) // =&gt; Optional(2)</span></div><div><span><br></span></div></div></div><div>-DW</div><div><br></div><div><div><blockquote type="cite"><div>On Dec 3, 2015, at 3:42 PM, Chris Lattner &lt;<a href="mailto:clattner@apple.com" target="_blank">clattner@apple.com</a>&gt; wrote:</div><br><div><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">“if let foo {“ is a frequently proposed extension to the syntax, but it is not one that we’re likely to ever add.</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">I agree that this is a common pattern, and it would allow you to “write less code”, but that isn’t the goal of Swift.  Since code is read more often than it is written, the real goal behind Swift is to let you write “more readable code” by eliminating boilerplate and other noise.<span> </span></span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">Reducing syntax isn’t itself a goal, particularly if the result could/would be confusing for someone who has to read and maintain your code later.</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">-Chris</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"></div></blockquote></div><br></div></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=CzM39owGTpkJ1zyGXnrRVEXja65D5KHvjV3-2BNib8-2FAKnkgf4b7twADRpfJDRbUOb8EUY9KPcK-2BF-2F5k08SA-2FcLcnZV6HMYK0sZ8em5ZT70hH5ulQkMBX0nrkRmmolFdVFvH2ELdrwYbnLzlY-2BP0Y82RbLqWonVVbuI5igD-2FoEyilmsjWkGhy9rX31P1kc4vQgk1eF8j3dRjFUIQBepMLetDY9A8N8Ej0YkrRYhQb3DZ8-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0px!important;margin:0px!important;padding:0px!important"></div></blockquote><blockquote type="cite" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=vC-2FQIU-2BCsLz-2Fl3B9m6u7iK-2B0lKodY1r4omFmZD8Y0qbYDNzpBDqgF-2FDEmmyNyPF1V-2BeDD43aBg-2F26fz-2FO0vMnefPpiOQ3HipuNMs2R7NcV9LSH3lo21AgJFpWNqUbgIdINhg-2BJIzPDAbZEDoKVkkVebwiDo0MpkcDs3ceO1eweJ9gA1g1-2FZkqEiIMlSBJpKAfgdxhhAC1aa-2FVWI6aOP8MzrJrWsDlv9m4cnbZek-2BIPU-3D" alt="" width="1" height="1" border="0" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;min-height:1px!important;width:1px!important;border-width:0px!important;margin:0px!important;padding:0px!important"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important"><span> </span>_______________________________________________</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">swift-evolution mailing list</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><a href="mailto:swift-evolution@swift.org" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">swift-evolution@swift.org</a><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br></div></div></div></div><div style="word-wrap:break-word"><div><div></div></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=4Q3dO0ELn940F2HNV6NWP3n6-2BFmLgXvEeytAtbr-2BgeCqmhmSGIcweIjxme7l0lgueW0HYU2dLt7wrBTIfh-2FgvLR774Be407sAEGqRESa1FOTtAlhOO-2FSjuZYx9lDdHzB03xiICskPGu6cAhsYo3iiHzBWe6xyCWpDMM-2FqrHqjYp-2F2XTS6l4eeiK9V9ADaqkvpYGikSDUzRPEKUJm-2BbgFO982yNvpTyE4-2BvcjFfnlyUg-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important">
</div>
_______________________________________________<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" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div>