<div dir="ltr">On Sun, Jun 12, 2016 at 9:23 AM, L. Mihalkovic <span dir="ltr"><<a href="mailto:laurent.mihalkovic@gmail.com" target="_blank">laurent.mihalkovic@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div><div class="h5"><div><br></div><div>On Jun 12, 2016, at 3:21 PM, Thorsten Seitz <<a href="mailto:tseitz42@icloud.com" target="_blank">tseitz42@icloud.com</a>> wrote:<br><br></div><blockquote type="cite"><div><br><div><blockquote type="cite"><div>Am 12.06.2016 um 12:02 schrieb L Mihalkovic <<a href="mailto:laurent.mihalkovic@gmail.com" target="_blank">laurent.mihalkovic@gmail.com</a>>:</div><br><div><div style="word-wrap:break-word"><br><div><blockquote type="cite"><div>On Jun 11, 2016, at 11:45 PM, Xiaodi Wu <<a href="mailto:xiaodi.wu@gmail.com" target="_blank">xiaodi.wu@gmail.com</a>> wrote:</div><br><div><br><br 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 class="gmail_quote" 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">On Sat, Jun 11, 2016 at 3:37 PM, Thorsten Seitz<span> </span><span dir="ltr"><<a href="mailto:tseitz42@icloud.com" target="_blank">tseitz42@icloud.com</a>></span><span> </span>wrote:<br><blockquote class="gmail_quote" 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"><div dir="auto"><div><div><div></div><div><br></div><div><br>Am 11.06.2016 um 22:29 schrieb L. Mihalkovic <<a href="mailto:laurent.mihalkovic@gmail.com" target="_blank">laurent.mihalkovic@gmail.com</a>>:<br><br></div><blockquote type="cite"><div><div><br></div><div><br>On Jun 11, 2016, at 9:53 PM, Thorsten Seitz via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br><br></div><blockquote type="cite"><div><div></div><div><br></div><div><br>Am 10.06.2016 um 18:28 schrieb Xiaodi Wu via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>>:<br><br></div><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Jun 10, 2016 at 6:10 AM, Karl<span> </span><span dir="ltr"><<a href="mailto:razielim@gmail.com" target="_blank">razielim@gmail.com</a>></span><span> </span>wrote:<br><blockquote class="gmail_quote" 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"><div style="word-wrap:break-word"><div>-1</div><span><div><br><blockquote type="cite"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>* Swift is explicitly a C-family language. In most or all other C-family languages, for loop statements allow specification of conditions for exiting the loop but not for filtering. Therefore, Swift's use of `where` is unprecedented and needs to be learned anew by every user of Swift.</div></div></div></div></blockquote><br></div></span><div>When was this decided? I distinctly remember some bloke under Craig Federighi’s hair saying that it was time to “move beyond” C and essentially ditch legacy conventions which no longer make sense.</div></div></blockquote><div><br></div><div>I think you misunderstood my argument here. I don't mean that we should yoke ourselves to C conventions, and we should absolutely ditch C convention when it doesn't make sense. The big-picture argument here is that `where` doesn't pass the bar of correcting a C convention that no longer makes sense.</div><div><br></div><div>FWIW, on the topic of syntax choices, here is what Chris Lattner had to say on this list:</div><div><br></div><blockquote class="gmail_quote" 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">Kevin got it exa<b style="background-color:rgb(255,255,102)">c</b>tly right, but I’d expand that last bit a bit to:<br>“… pi<b style="background-color:rgb(255,255,102)">c</b>king the one that is most familiar to programmers in the extended<span> </span><b style="background-color:rgb(255,255,102)">C</b><span> </span><b style="background-color:rgb(255,255,102)">family</b><span> </span>is a good idea.["]<br>The extended<span> </span><b style="background-color:rgb(255,255,102)">C</b><span> </span><b style="background-color:rgb(255,255,102)">family</b><span> </span>of language (whi<b style="background-color:rgb(255,255,102)">c</b>h in<b style="background-color:rgb(255,255,102)">c</b>ludes<span> </span><b style="background-color:rgb(255,255,102)">C</b>,<span> </span><b style="background-color:rgb(255,255,102)">C</b>++, Obj<b style="background-color:rgb(255,255,102)">C</b>, but also<span> </span><b style="background-color:rgb(255,255,102)">C</b>#, Java, Javas<b style="background-color:rgb(255,255,102)">c</b>ript, and more) is<br>an extremely popular and widely used set of languages that have a lot of surfa<b style="background-color:rgb(255,255,102)">c</b>e-level similarity. I<br>don’t<span> </span><b style="background-color:rgb(255,255,102)">c</b>laim to know the design rationale of all of these languages, but I surmise that this is not an<br>a<b style="background-color:rgb(255,255,102)">c</b><b style="background-color:rgb(255,255,102)">c</b>ident: programmers move around and work in different languages, and this allows a non-expert in the<br>language to understand what is going on. While there are things about<span> </span><b style="background-color:rgb(255,255,102)">C</b><span> </span>that are really unfortunate IMO<br>(e.g. the de<b style="background-color:rgb(255,255,102)">c</b>larator/de<b style="background-color:rgb(255,255,102)">c</b>laration spe<b style="background-color:rgb(255,255,102)">c</b>ifier part of the grammar) there is a lot of goodness in the basi<b style="background-color:rgb(255,255,102)">c<br></b>operator set, fo<b style="background-color:rgb(255,255,102)">c</b>us on dot syntax, and more.<br>I do agree that there are some benefits to dit<b style="background-color:rgb(255,255,102)">c</b>hing bra<b style="background-color:rgb(255,255,102)">c</b>es and relying on indentation instead, but there are<br>also downsides. Deviating from the<span> </span><b style="background-color:rgb(255,255,102)">C</b><span> </span><b style="background-color:rgb(255,255,102)">family</b><span> </span>in this respe<b style="background-color:rgb(255,255,102)">c</b>t would have to provide<span> </span><b>*overwhelmingly*</b><span> </span>large <br><span>advantages for us to take su</span><b style="background-color:rgb(255,255,102)">c</b><span>h a plunge, and they simply don’t exist.</span></blockquote><div> </div><blockquote class="gmail_quote" 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"><div style="word-wrap:break-word"><div>As I understand it, Swift is a new language with new conventions. It is desirable to align as many of those as possible with existing conventions so as to be easily learned, but if you limit Swift to other languages conventions you deny it any identity. Did Python ask anybody’s opinion before dropping curly-braces? Did people learn whatever Perl is supposed to be? Look at C’s hieroglyphic for loops! </div></div></blockquote><div><br></div><div>I don't think we disagree here.</div><div> </div><blockquote class="gmail_quote" 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"><div style="word-wrap:break-word"><div><br></div><div>Realistically, “for … in … while” is not going to cause incredible confusion. Removing it would cause a lot of frustration. You can’t on the one hand say our users are comfortable with the axioms of C’s hieroglyphic loops, and on the other hand say “for x in y while" is confusing.</div><span><div><br></div><div><blockquote type="cite"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>Again, as I said, once you've mastered something, by definition you find it not confusing. Why should we doom x% of new users to writing a loop incorrectly at least once when we don't have to?</div></div></div></div></blockquote></div></span><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>Ah, but if you’re not “doomed” to failing once, how will you ever master anything? Nobody knew how to write a C for-loop until someone showed them (and even then…). Nobody is going to just open a REPL and start writing code, with zero prior understanding of what Swift syntax looks like.</div></div></div></div></div></div></blockquote><div><br></div><div>The thought here is along the lines of what Chris said, quoted above, and repeated here: "The extended C family of language [...] is an extremely popular and widely used set[;] programmers move around and work in different languages, and [aligning to expectations arising from other C family languages] allows a non-expert in the language to understand what is going on." By contrast, the `where` clause violates that expectation and I do not see "overwhelmingly large advantages" for doing so.</div></div></div></div></div></blockquote><div><br></div>What about C#'s `where` then? As C# is a member of the C family languages `where` is not violating expectations!</div></blockquote><div><br></div><div>Where is not exactly a part of c# it belongs to linq</div></div></blockquote><div><br></div></div></div>And that is not a part of C#??</div></blockquote><div><br></div><div>SQL is a domain-specific language, and LINQ is an internal domain-specific language with a language extension for C#. Neither is a general purpose language.<br></div><div><br></div><div>Your example actually goes to one of Laurent's points. Should the Swift core team or an enterprising community member propose a set of similarly powerful tools, along with a set of language extensions that add syntactic sugar for them, I (and I think Laurent, if I understand him correctly) would absolutely be in favor of such an addition. But as it is, `where` is an odd duckling. Just as you say, it looks like a component of a query language, but it does no such thing. In a for loop, it does some filtering, but until recently it functioned like a comma in `while` loops. Look at those other keywords which make this sugar possible in C#: in your example, `from` and `select`. We don't have any of that intrastructure in Swift.</div><div> </div></div></div></blockquote><div><br></div><div>IMHO the team has taken an Ockham Axe to the grammar: in the presence of multiple ways to produce the same or an acceptable stand-in (for eg when the only difference is an acceptable temporary perf setback), then the solution requiring the least assumptions on the compiler wins. </div><div><br></div><div>I would even extend this rule with the corollary that between an assumption materialized as a type checker rule and an assumption materialized as a full blown extra language keyword, there might be a bias to accept the former if it kills the latter. But this is just my personal inference of what their decision heuristic might be based solely on what I saw. My sole interest in trying to understand their decision making process is to try to avoid proposals that have little to no chance to go anywhere, as well as trying to present ones that will align better with where the language is going.</div><div><br></div><div>In this instance, WHERE is a heavy assumption on the compiler for no greater gain than filters can provide. So I think we save the WHERE keyword for an outcome that will be really worth it! Something along the idea of Linq, but with a proper Swift feel to it. What does it look like? I cannot say yet. But the good news is that having taken WHERE out now will make that next step a purely additive process (nothing will be taken out then, but a big thing will be gained). </div></div></div></div></blockquote><div><br></div>I am all for extending `for` to be more like Scala’s `for`-expression or Haskell’s `do`-notation. LINQ might be too focused on querying.</div><div>Extending the current `where` to be syntax sugar for `filter` would be quite straightforward, though, so I’m not sure whether removing it first is really necessary. </div><div>That was not object of the pitch to retire `where` from `for`-loops, though. Instead the argument was (and still is) that `where` might be misunderstood there by beginners and should therefore be removed. This argument would apply to an extended `where` unchanged, because I can still write the exact same code as being criticized now and can even do more complicated things which would by even more hard to understand for beginners.</div><div>That’s the argument I disagree with.</div><div><br></div><div><br><blockquote type="cite"><div><div style="word-wrap:break-word"><div><div><br></div><br><blockquote type="cite"><div><div class="gmail_quote" 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"><blockquote class="gmail_quote" 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"><div dir="auto"><div>The following is an example from MSDN with `where` clearly beaing a keyword:</div><div><br><div><pre style="padding:5px;margin-top:0px;margin-bottom:0px;overflow:auto;word-wrap:normal"><font face="UICTFontTextStyleTallBody"><span style="white-space:normal;background-color:rgba(255,255,255,0)"><b>var</b><span> </span>numQuery =<span> </span><b>from</b><span> </span>num<span> </span><b>in</b><span> </span>numbers<span> </span><b>where</b><span> </span>(num % 2) == 0<span> </span><b>select</b><span> </span>num;</span></font><span style="font-size:13px;font-family:Consolas,Courier,monospace!important">
</span></pre></div></div></div></blockquote></div></div></blockquote><div><br></div><div><br></div><div>Here is food for your thoughts, you think WHERE is a keyword?! then look at this:</div><div><br></div><div><div><font color="#719ecf" face="Menlo">var numbers = new int[]{0,1,23,4,5,6,7,87,9};</font></div><div><font color="#719ecf" face="Menlo">var numQuery = from num in numbers where (num % 2) == 0 select num;</font></div><div><br></div></div><div><div>Program does not compile:</div><div><br></div></div><div><font color="#ff2600"><font face="Menlo">// </font><font face="Menlo">Error CS1935: An implementation of `Where' query expression pattern could not be found. Are you missing `System.Linq' using directive or `System.Core.dll' assembly reference? (CS1935) (SessionsFinder)</font></font></div><div><font face="Menlo" color="#ff2600"><br></font></div><div><div><font face="Menlo"><span style="color:rgb(113,158,207)">using</span><span style="color:rgb(238,238,236)"> </span></font><span style="font-family:Menlo;color:rgb(136,138,133)">System</span><span style="font-family:Menlo;color:rgb(136,138,133)">.</span><span style="font-family:Menlo;color:rgb(136,138,133)">Linq</span><span style="font-family:Menlo;color:rgb(136,138,133)">;</span></div><div><div><font color="#719ecf" face="Menlo">var numbers = new int[]{0,1,23,4,5,6,7,87,9};</font></div><div><font color="#719ecf" face="Menlo">var numQuery = from num in numbers where (num % 2) == 0 select num;</font></div><div><br></div></div></div><div><div>That program does compiles and runs fine. This tells you that “where" is not at all the ordinary keyword that it appears to be. hence my “it is not C# per-se, it is Linq”. </div></div></div></div></div></blockquote><div><br></div><div>Digging into <a href="https://msdn.microsoft.com/en-us/library/bb397909.aspx" target="_blank">https://msdn.microsoft.com/en-us/library/bb397909.aspx</a> and <a href="https://msdn.microsoft.com/en-us/library/the35c6y.aspx" target="_blank">https://msdn.microsoft.com/en-us/library/the35c6y.aspx</a> tells me the following:</div><div>(1) `from`, `where` etc. are contextual keywords, but they are nonetheless keywords of C# and expressly *not* a specific feature of LINQ: "Although these new features are all used to a degree with LINQ queries, they are not limited to LINQ and can be used in any context where you find them useful."</div><div>(2) the compiler translates them into standard method calls (like Scala’s `for`-expression or Haskell’s `do`-notation). That is an integral part of C#.</div><div>(3) your error message originates from not having an implementation of a `Where`-method in scope. You could have provided one yourself instead of `using System.Linq`.</div><div><br></div></div></div></blockquote><div><br></div></div></div><div>Of course the compiler knows about it... My exact wording was "ordinary keyword" implying, "it is one, just not in the sense you are giving it right now". Knowing you would want to dig further I had to find a description that was true albeit leaving the fine details out (i doubt too may actually care about the distinction between contextual and non-contextual kwd, or the fact that sql is turing complete ;) ). </div><div><br></div><div>My thought is to accept the downgrading from its current status because its complete behavior is limited and hetched in blood inside the grammar, therefore not extensible without grammar alterations; thereby leaving the door open for a future re-introduction ala-Linq in v4+. I use the term "ala-linq" as a placeholder for "some sort of more dynamic behavior resulting from a close collaboration between compiler, stdlib, runtime and user code". And i still believe nobody outside doug, joe, chris, or jordan cares about the actual implementation details. </div><div><br></div><div>Again, this is just a personal view on what looks IMHO like a great opportunity.</div></div></blockquote><div><br></div><div>Well said. Like you, I don't know what the core team's feelings would be with respect to contextual sugar for domain-specific uses. IMHO, it is a very neat concept. If it does arrive in Swift 4+, then `where` as sugar for `filter()` should come with that. If that's not the direction that the core team wants to go, I fail to see why filtering a sequence specifically as part of a loop should be privileged above any other useful operation that would have a similarly strong claim to sugar.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><span class=""><blockquote type="cite"><div><div><blockquote type="cite"><div><div style="word-wrap:break-word"><div><div><div>And if you still wonder, then rewrite the code so that “WHERE” no longer looks like a keyword:</div><div><br></div><div><font color="#0433ff">var numQuery2 = numbers.Where( num => num %2 == 0);</font><span style="color:rgb(4,51,255);white-space:pre-wrap">        </span><font color="#4f7a28">// exact same result as numQuery1</font></div></div></div></div></div></blockquote><div><br></div>That’s exactly what I expected as it is the standard way syntactic language sugar is mapped to customizable behavior. Haskell’s `do`-notation or Scala’s `for`-expression are mapped likewise to functions on the types used.</div><div><br></div><div>-Thorsten</div><div><br></div><div><br><blockquote type="cite"><div><div style="word-wrap:break-word"><div><div><div><br></div><div><br></div><div>These are other real life examples from a OS X tool I wrote recently: </div><div><br></div><div><font face="Menlo"><span style="color:#3364a4">IEnumerable</span><span style="color:#222222"><</span><span style="color:#3364a4">Task</span><span style="color:#222222"><</span><span style="color:#3364a4">Session</span><span style="color:#222222">>></span><span style="color:#222222"> </span><span style="color:#222222">asyncOps</span><span style="color:#222222"> </span><span style="color:#222222">=</span><span style="color:#222222"> </span><span style="color:#009695">from</span><span style="color:#222222"> session </span><span style="color:#009695">in</span><span style="color:#222222"> </span><span style="color:#222222">sessions</span><span style="color:#222222">.</span><span style="color:#222222">Values</span><span style="color:#222222"> </span><span style="color:#009695">select</span><span style="color:#222222"> parseSessionDetails</span><span style="color:#222222">(</span><span style="color:#222222">updater</span><span style="color:#222222">,</span><span style="color:#222222"> </span><span style="color:#222222">parser</span><span style="color:#222222">,</span><span style="color:#222222"> </span><span style="color:#222222">session</span><span style="color:#222222">)</span><span style="color:#222222">;</span></font></div></div><div><span style="font-family:Menlo;color:rgb(0,150,149)">var</span><span style="font-family:Menlo;color:rgb(34,34,34)"> </span><span style="font-family:Menlo;color:rgb(34,34,34)">ul</span><span style="font-family:Menlo;color:rgb(34,34,34)"> </span><span style="font-family:Menlo;color:rgb(34,34,34)">=</span><span style="font-family:Menlo;color:rgb(34,34,34)"> </span><span style="font-family:Menlo;color:rgb(34,34,34)">node</span><span style="font-family:Menlo;color:rgb(34,34,34)">.</span><span style="font-family:Menlo;color:rgb(34,34,34)">Descendants</span><span style="font-family:Menlo;color:rgb(34,34,34)">()</span><span style="font-family:Menlo;color:rgb(34,34,34)">.</span><span style="font-family:Menlo;color:rgb(34,34,34)">Where</span><span style="font-family:Menlo;color:rgb(34,34,34)">(</span><span style="font-family:Menlo;color:rgb(34,34,34)">x</span><span style="font-family:Menlo;color:rgb(34,34,34)"> </span><span style="font-family:Menlo;color:rgb(34,34,34)">=</span><span style="font-family:Menlo;color:rgb(34,34,34)">></span><span style="font-family:Menlo;color:rgb(34,34,34)"> </span><span style="font-family:Menlo;color:rgb(34,34,34)">x</span><span style="font-family:Menlo;color:rgb(34,34,34)">.</span><span style="font-family:Menlo;color:rgb(34,34,34)">Name </span><span style="font-family:Menlo;color:rgb(34,34,34)">==</span><span style="font-family:Menlo;color:rgb(34,34,34)"> </span><span style="font-family:Menlo;color:rgb(219,113,0)">"</span><span style="font-family:Menlo;color:rgb(219,113,0)">ul</span><span style="font-family:Menlo;color:rgb(219,113,0)">"</span><span style="font-family:Menlo;color:rgb(34,34,34)">)</span><span style="font-family:Menlo;color:rgb(34,34,34)">.</span><span style="font-family:Menlo;color:rgb(34,34,34)">First</span><span style="font-family:Menlo;color:rgb(34,34,34)">()</span><span style="font-family:Menlo;color:rgb(34,34,34)">;</span></div><div><br></div><div><br></div></div></div></div></blockquote></div><br></div></blockquote></span></div></blockquote></div><br></div></div>