<div dir="ltr"><div>I don&#39;t know if this will help clarify things, so take or leave as you like:</div><div><br></div><div>I wasn&#39;t aware before this discussion that the first of the comma-separated expressions of an if let could be just an &#39;if&#39;.<br></div><div><br></div><div>Now I have learned it, it just seems to be an odd construction: the first clause of an if can be a boolean expression, a let binding, a var binding or a case let/var binding, and then after the first comma every boolean expression must be preceded by &#39;where&#39;. There&#39;s no obligation for the boolean expression to relate to the constant or variable just bound.</div><div><br></div><div>My original premise was simply to allow boolean expressions and binding expressions to alternate within the if; boolean operators like &amp; and | would separate boolean expressions, commas would separate binding expressions, and semi-colons would allow alternating from one to the other. I hadn&#39;t anticipated that this would deprecate any existing code; a let followed by a var in the if would still be comma-separated binding expressions - but I&#39;m not objecting to deprecating something if it makes the code clearer.</div><div><br></div><div>So (and I apologise for the trivialised example) my proposed change would be that this:</div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">if</span> a == <span style="color:rgb(39,42,216)">5</span>, <span style="color:rgb(187,44,162)">let</span> b = c <span style="color:rgb(187,44,162)">where</span> array.<span style="color:rgb(112,61,170)">count</span> &gt; <span style="color:rgb(39,42,216)">5</span>, <span style="color:rgb(187,44,162)">let</span> d = c, <span style="color:rgb(187,44,162)">var</span> e = array[<span style="color:rgb(39,42,216)">0</span>], f = array[<span style="color:rgb(39,42,216)">1</span>] <span style="color:rgb(187,44,162)">where</span> e == f, <span style="color:rgb(187,44,162)">case</span> .Some(<span style="color:rgb(187,44,162)">let</span> g) = c <span style="color:rgb(187,44,162)">where</span> g.<span style="color:rgb(112,61,170)">characters</span>.<span style="color:rgb(112,61,170)">count</span> &gt; <span style="color:rgb(39,42,216)">2</span> { }</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-family:arial,sans-serif;font-size:small">would become</span><br></p></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">if</span> a == <span style="color:rgb(39,42,216)">5</span>; <span style="color:rgb(187,44,162)">let</span> b = c; array.<span style="color:rgb(112,61,170)">count</span> &gt; <span style="color:rgb(39,42,216)">5</span>; <span style="color:rgb(187,44,162)">let</span> d = c, <span style="color:rgb(187,44,162)">var</span> e = array[<span style="color:rgb(39,42,216)">0</span>], f = array[<span style="color:rgb(39,42,216)">1</span>] <span style="color:rgb(187,44,162)">where</span> e == f; <span style="color:rgb(187,44,162)">case</span> .Some(<span style="color:rgb(187,44,162)">let</span> g) = c <span style="color:rgb(187,44,162)">where</span> g.characters.count &gt; <span style="color:rgb(39,42,216)">2 </span>{ }<br></p></div><div><br></div><div>So, mostly the same, but &#39;where&#39; can be used only where it clarifies to the reader that it&#39;s qualifying a binding, rather than being used because it&#39;s the only way to follow a binding expression with a boolean expression.</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Feb 5, 2016 at 12:04 AM, James Hillhouse IV 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">Here’s a question that Drew raised as he was educating me on this discussion. Given that the following works, are you proposing to deprecate,<div><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:#bb2ca2">if</span> <span style="color:#bb2ca2">let</span> a = <span style="color:#272ad8">2</span>, <span style="color:#bb2ca2">var</span> b = <span style="color:#272ad8">3</span>, <span style="color:#bb2ca2">let</span> c = <span style="color:#272ad8">4</span>, <span style="color:#bb2ca2">var</span> d = <span style="color:#272ad8">5</span>{ } <span style="color:#008400">// 1</span></div></div><div><br></div><div>in favor of?</div><div><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:#bb2ca2">if</span> <span style="color:#bb2ca2">let</span> a = <span style="color:#272ad8">2;</span> <span style="color:#bb2ca2">var</span> b = <span style="color:#272ad8">3;</span> <span style="color:#bb2ca2">let</span> c = <span style="color:#272ad8">4;</span> <span style="color:#bb2ca2">var</span> d = <span style="color:#272ad8">5</span>{ } <span style="color:#008400">// 2</span></div></div><div><br></div><div>If semi-colon is still being considered, can Joe or Jordon clarify?</div><span class=""><div><br><div><blockquote type="cite"><div>On Feb 2, 2016, at 7:40 PM, Joe Groff via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</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;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><blockquote type="cite"><div><br>On Feb 2, 2016, at 5:13 PM, Jordan Rose via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br><div><div style="word-wrap:break-word"><br><div><blockquote type="cite"><div>On Feb 2, 2016, at 16:53, Ross O&#39;Brien via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br><div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">For example: getting the first element from an array of optionals. Here&#39;s my sample trivial example:</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="white-space:pre-wrap">        </span><span style="color:rgb(187,44,162)">var</span><span> </span>array : [<span style="color:rgb(112,61,170)">Int</span>?] = []</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="white-space:pre-wrap">        </span><span style="color:rgb(187,44,162)">if</span><span> </span><span style="color:rgb(187,44,162)">let</span><span> </span>x = array[<span style="color:rgb(39,42,216)">0</span>]<span> </span><span style="color:rgb(187,44,162)">where</span><span> </span>array.<span style="color:rgb(112,61,170)">count</span><span> </span>&gt;<span> </span><span style="color:rgb(39,42,216)">0</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="white-space:pre-wrap">        </span>{</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="white-space:pre-wrap">                </span><span style="color:rgb(61,29,129)">print</span>(x)</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="white-space:pre-wrap">        </span>}</div></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">This code doesn&#39;t work. The array index is out of range. But there&#39;s no way I know of to rearrange the &#39;if&#39; to ensure the array isn&#39;t empty before binding to the first element - the developer has to write a nested if statement.</div></div></blockquote><br></div><div>We already allow this, with commas:</div><br><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div>var array: [Int?] = []</div><div>if !array.isEmpty, let x = array[0] {</div><div>  print(x)</div><div>}</div></blockquote></div></div></blockquote></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"><div 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">That&#39;s true, but there are some problematic ambiguities with our current syntax, since &#39;let&#39; and &#39;case&#39; conditions both admit multiple sub-conditions also separated by commas, e.g. &#39;if let x = y, y = z { }&#39; or &#39;if case let x = y, let y = z&#39;. Using &#39;;&#39; for this purpose would be less ambiguous.</div></div></blockquote></div><br></div></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>