<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, May 31, 2016 at 2:32 PM, Christopher Kornher via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
> On May 31, 2016, at 1:00 PM, Erica Sadun via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br>
><br>
><br>
>> On May 31, 2016, at 12:52 PM, Xiaodi Wu <<a href="mailto:xiaodi.wu@gmail.com">xiaodi.wu@gmail.com</a>> wrote:<br>
>> These lines of reasoning are what have compelled me to conclude that `where` might not be salvageable.<br>
><br>
> To which, I'd add: `where` suggests there's a subordinate and semantic relationship between the primary condition and the clause. There's no way as far as I know this to enforce it in the grammar and the proposal allows both clauses to be stated even without the connecting word.<br>
<br>
</span>OK. I am naive enough to try to informally define a rule that would make “where” required and cover all (?) cases in the proposal:<br>
<br>
‘where’ is required after an if-let for any clause involving a variable or constant defined in that 'if let. All boolean expressions after the ‘where’ must reference at least one of constants defined by the ‘if let'<br>
<br>
Allowed:<br>
<br>
let a = a, b=b where b > 10 && a > 5 && b> a<br>
<br>
<br>
Not allowed:<br>
…<br>
let a = a<br>
let b = b where b > 10 && a > 5<br></blockquote><div><br></div><div>Why would this not be allowed by your rule? You're making use of `b` in your where clause. As I demonstrated above, essentially any assertion can be rewritten to work around your rule. In general:</div><div><br></div><div>```</div><div>let y = y where x < z</div><div>```</div><div><br></div><div>can be trivially (and awfully) rewritten as<br></div><div><br></div><div>```</div><div>let y = y where (y.dynamicType == y.dynamicType && x < z)</div><div>```</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
b > a<br>
...<br>
<br>
…<br>
let a = a<br>
let b = b where b > 10<br>
a > 5<br>
b > a<br>
…<br>
<br>
This requires the use of commas because all inter-related ‘if let’ constants must be associated with a single ‘where'<br>
<br>
This makes the use of ‘&&’ more natural, since everything to the right of “where” is a boolean expression<br>
<br>
The formal grammar is left as an exercise :)<br>
<br>
The downside:<br>
<br>
I would not have to answer all the ‘Why won’t this compile?’ questions on stack overflow. Of course, I would not want to do that for the current syntax, either.<br>
<span class="im HOEnZb"><br>
<br>
> You could make a vague argument, I suppose, for renaming `where` to `when` but all in all, even killing `where` we benefit with better expressive capabilities and a simpler grammar.<br>
><br>
> -- E<br>
><br>
</span><div class="HOEnZb"><div class="h5">> _______________________________________________<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>
_______________________________________________<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>
</div></div></blockquote></div><br></div></div>