<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Ross,<div class=""><div class=""><br class=""></div></div><div class="">Thanks for the clarification of what you’re trying to do. </div><div class=""><br class=""></div><div class="">Jim</div><div class=""><br class=""></div><div class=""><div><blockquote type="cite" class=""><div class="">On Feb 4, 2016, at 6:58 PM, Ross O'Brien <<a href="mailto:narrativium@gmail.com" class="">narrativium@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="">I don't know if this will help clarify things, so take or leave as you like:</div><div class=""><br class=""></div><div class="">I wasn't aware before this discussion that the first of the comma-separated expressions of an if let could be just an 'if'.<br class=""></div><div class=""><br class=""></div><div class="">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 'where'. There's no obligation for the boolean expression to relate to the constant or variable just bound.</div><div class=""><br class=""></div><div class="">My original premise was simply to allow boolean expressions and binding expressions to alternate within the if; boolean operators like & and | would separate boolean expressions, commas would separate binding expressions, and semi-colons would allow alternating from one to the other. I hadn'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'm not objecting to deprecating something if it makes the code clearer.</div><div class=""><br class=""></div><div class="">So (and I apologise for the trivialised example) my proposed change would be that this:</div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="color:rgb(187,44,162)" class="">if</span> a == <span style="color:rgb(39,42,216)" class="">5</span>, <span style="color:rgb(187,44,162)" class="">let</span> b = c <span style="color:rgb(187,44,162)" class="">where</span> array.<span style="color:rgb(112,61,170)" class="">count</span> > <span style="color:rgb(39,42,216)" class="">5</span>, <span style="color:rgb(187,44,162)" class="">let</span> d = c, <span style="color:rgb(187,44,162)" class="">var</span> e = array[<span style="color:rgb(39,42,216)" class="">0</span>], f = array[<span style="color:rgb(39,42,216)" class="">1</span>] <span style="color:rgb(187,44,162)" class="">where</span> e == f, <span style="color:rgb(187,44,162)" class="">case</span> .Some(<span style="color:rgb(187,44,162)" class="">let</span> g) = c <span style="color:rgb(187,44,162)" class="">where</span> g.<span style="color:rgb(112,61,170)" class="">characters</span>.<span style="color:rgb(112,61,170)" class="">count</span> > <span style="color:rgb(39,42,216)" class="">2</span> { }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-family:arial,sans-serif;font-size:small" class="">would become</span><br class=""></div></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="color:rgb(187,44,162)" class="">if</span> a == <span style="color:rgb(39,42,216)" class="">5</span>; <span style="color:rgb(187,44,162)" class="">let</span> b = c; array.<span style="color:rgb(112,61,170)" class="">count</span> > <span style="color:rgb(39,42,216)" class="">5</span>; <span style="color:rgb(187,44,162)" class="">let</span> d = c, <span style="color:rgb(187,44,162)" class="">var</span> e = array[<span style="color:rgb(39,42,216)" class="">0</span>], f = array[<span style="color:rgb(39,42,216)" class="">1</span>] <span style="color:rgb(187,44,162)" class="">where</span> e == f; <span style="color:rgb(187,44,162)" class="">case</span> .Some(<span style="color:rgb(187,44,162)" class="">let</span> g) = c <span style="color:rgb(187,44,162)" class="">where</span> g.characters.count > <span style="color:rgb(39,42,216)" class="">2 </span>{ }<br class=""></div></div><div class=""><br class=""></div><div class="">So, mostly the same, but 'where' can be used only where it clarifies to the reader that it's qualifying a binding, rather than being used because it's the only way to follow a binding expression with a boolean expression.</div><div class=""><br class=""></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Fri, Feb 5, 2016 at 12:04 AM, James Hillhouse IV via swift-evolution <span dir="ltr" class=""><<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="">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 class=""><br class=""></div><div class=""><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="color:#bb2ca2" class="">if</span> <span style="color:#bb2ca2" class="">let</span> a = <span style="color:#272ad8" class="">2</span>, <span style="color:#bb2ca2" class="">var</span> b = <span style="color:#272ad8" class="">3</span>, <span style="color:#bb2ca2" class="">let</span> c = <span style="color:#272ad8" class="">4</span>, <span style="color:#bb2ca2" class="">var</span> d = <span style="color:#272ad8" class="">5</span>{ } <span style="color:#008400" class="">// 1</span></div></div><div class=""><br class=""></div><div class="">in favor of?</div><div class=""><br class=""></div><div class=""><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="color:#bb2ca2" class="">if</span> <span style="color:#bb2ca2" class="">let</span> a = <span style="color:#272ad8" class="">2;</span> <span style="color:#bb2ca2" class="">var</span> b = <span style="color:#272ad8" class="">3;</span> <span style="color:#bb2ca2" class="">let</span> c = <span style="color:#272ad8" class="">4;</span> <span style="color:#bb2ca2" class="">var</span> d = <span style="color:#272ad8" class="">5</span>{ } <span style="color:#008400" class="">// 2</span></div></div><div class=""><br class=""></div><div class="">If semi-colon is still being considered, can Joe or Jordon clarify?</div><span class=""><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Feb 2, 2016, at 7:40 PM, Joe Groff via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>> wrote:</div><br class=""><div class=""><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" class=""><blockquote type="cite" class=""><div class=""><br class="">On Feb 2, 2016, at 5:13 PM, Jordan Rose via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>> wrote:</div><br class=""><div class=""><div style="word-wrap:break-word" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Feb 2, 2016, at 16:53, Ross O'Brien via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>> wrote:</div><br class=""><div class=""><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" class="">For example: getting the first element from an array of optionals. Here'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" class=""><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="white-space:pre-wrap" class="">        </span><span style="color:rgb(187,44,162)" class="">var</span><span class=""> </span>array : [<span style="color:rgb(112,61,170)" class="">Int</span>?] = []</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="white-space:pre-wrap" class="">        </span><span style="color:rgb(187,44,162)" class="">if</span><span class=""> </span><span style="color:rgb(187,44,162)" class="">let</span><span class=""> </span>x = array[<span style="color:rgb(39,42,216)" class="">0</span>]<span class=""> </span><span style="color:rgb(187,44,162)" class="">where</span><span class=""> </span>array.<span style="color:rgb(112,61,170)" class="">count</span><span class=""> </span>><span class=""> </span><span style="color:rgb(39,42,216)" class="">0</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="white-space:pre-wrap" class="">        </span>{</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="white-space:pre-wrap" class="">                </span><span style="color:rgb(61,29,129)" class="">print</span>(x)</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="white-space:pre-wrap" class="">        </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" class="">This code doesn't work. The array index is out of range. But there's no way I know of to rearrange the 'if' to ensure the array isn't empty before binding to the first element - the developer has to write a nested if statement.</div></div></blockquote><br class=""></div><div class="">We already allow this, with commas:</div><br class=""><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px" class=""><div class="">var array: [Int?] = []</div><div class="">if !array.isEmpty, let x = array[0] {</div><div class=""> print(x)</div><div class="">}</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" class=""><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" class="">That's true, but there are some problematic ambiguities with our current syntax, since 'let' and 'case' conditions both admit multiple sub-conditions also separated by commas, e.g. 'if let x = y, y = z { }' or 'if case let x = y, let y = z'. Using ';' for this purpose would be less ambiguous.</div></div></blockquote></div><br class=""></div></span></div><br class="">_______________________________________________<br class="">
swift-evolution mailing list<br class="">
<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
<br class=""></blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></div></body></html>