<div dir="ltr">On Mon, May 8, 2017 at 2:15 AM, David Hart <span dir="ltr">&lt;<a href="mailto:david@hartbit.com" target="_blank">david@hartbit.com</a>&gt;</span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><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"><br><div><span class="gmail-"><blockquote type="cite"><div>On 8 May 2017, at 09:09, Xiaodi Wu &lt;<a href="mailto:xiaodi.wu@gmail.com" target="_blank">xiaodi.wu@gmail.com</a>&gt; wrote:</div><br class="gmail-m_3980754445710470531Apple-interchange-newline"><div><div dir="ltr">On Mon, May 8, 2017 at 12:16 AM, David Hart <span dir="ltr">&lt;<a href="mailto:david@hartbit.com" target="_blank">david@hartbit.com</a>&gt;</span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><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"><span><div><br></div><div>On 7 May 2017, at 00:21, Xiaodi Wu via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br><br></div><blockquote type="cite"><div>To which human would it be misleading?<br><br>To the writer? No, because the compiler will warn you right away. By the time you&#39;re done with writing the first line, it&#39;ll warn you that Int and Double are unused variables. And if you try to use x and y, you get an error.<br><br>To the reader? Only if the writer knowingly wrote this misleading code. In other words, it&#39;s a nice puzzle, but no reader will encounter this in real-world code, unless they&#39;re being tormented by the writer on purpose.<br></div></blockquote><div><br></div></span><div>IMHO, the fact that the compiler warns you does no change the fact that it&#39;s a very confusing part of the language. It should not be an excuse for fixing it. Consistency teaches us to expect a type after a colon.</div></div></blockquote></div><br></div><div class="gmail_extra">Highly disagree. Consistency teaches us that variables can come after a colon.</div></div></div></blockquote><div><br></div></span><div>Correct. I meant to say that sentence in the context of the LHS of an assignment.</div></div></div></blockquote><div><br></div><div><div>As Adrian shows, enum case patterns have the exact same syntax during pattern matching, and you&#39;ll find the variable that&#39;s being bound written after a colon on the LHS:</div></div><div><br></div><div>```</div><div><div>enum Foo { case bar, baz(boo: Int) }</div><div><br></div><div>let foo = Foo.baz(boo: 42)</div><div><br></div><div>if case let .baz(boo: x) = foo {</div><div>  print(x) // Prints &quot;42&quot;.</div><div>}</div></div><div>```</div><div><br></div><div>There&#39;s a longstanding complaint that pattern matching in Swift is backwards in terms of what&#39;s on the LHS and what&#39;s on the RHS. Recall the numerous proposals on the list to introduce a `=~` operator that reverses LHS and RHS as compared to the current `~=`. (IIRC, the core team responded to say that they had tried it both ways and the current sequence was the more ergonomic of the two.) But, in any case, with respect to consistency with the rest of the language, tuple patterns with labels are *supremely* consistent.</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"><div style="word-wrap:break-word"><div><div>Can’t we even agree that the syntax is misleading?</div></div></div></blockquote><div><br></div><div>No! Until this conversation I would have laughed at the suggestion that *anyone* would find this even slightly misleading. Yes, Robert came up with a very clever puzzle. I&#39;ll bet you there are *plenty* of neat puzzles that you can come up with if you start naming your variables `Int` and `Double`. That does _not_ demonstrate that tuple patterns are misleading.</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"><div style="word-wrap:break-word"><div><span class="gmail-"><br><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra">```</div><div class="gmail_extra">func foo(bar: Int, baz: Int) {</div><div class="gmail_extra">  print(bar, baz)</div><div class="gmail_extra">}</div><div class="gmail_extra"><br></div><div class="gmail_extra">func foo(bar: Bool, baz: Bool) {</div><div class="gmail_extra">  print(bar, baz)</div><div class="gmail_extra">}</div><div class="gmail_extra"><br></div><div class="gmail_extra">let x = 42</div><div class="gmail_extra">let y = 43</div><div class="gmail_extra">foo(bar: x, baz: y)</div><div class="gmail_extra">// x and y are variables, and they come after the colon.</div><div class="gmail_extra">// We don&#39;t allow users to write `foo(bar x: Int, baz y: Int)`,</div><div class="gmail_extra">// even when there are overloads.</div><div class="gmail_extra">```</div><div class="gmail_extra"><br></div><div class="gmail_extra">There is nothing inconsistent about this part of the language.</div><div class="gmail_extra"><br></div><div class="gmail_extra"><br></div></div>
</div></blockquote></span></div><br></div></blockquote></div><br></div></div>