<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">I'd prefer to offer both ~= and =~, allowing the consumer to choose which side the pattern sits on.</div><div class=""><br class=""></div><div class="">-- E</div><div class=""><br class=""></div><br class=""><div><blockquote type="cite" class=""><div class="">On Apr 7, 2016, at 11:09 AM, David Owens II via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=us-ascii" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">It would be nice to know the rationale behind the choice of the current syntax. I agree that these seem more natural:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><font face="Menlo" class="">@warn_unused_result</font></div><div class=""><font face="Menlo" class="">public&nbsp;func&nbsp;~=&lt;I :&nbsp;ForwardIndexType&nbsp;where&nbsp;I&nbsp;:&nbsp;Comparable&gt;(value:&nbsp;I, pattern:&nbsp;Range&lt;I&gt;) -&gt;&nbsp;Bool</font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class="">@warn_unused_result</font></div><div class=""><font face="Menlo" class="">public&nbsp;func&nbsp;~=&lt;I :&nbsp;IntervalType&gt;(value:&nbsp;I.Bound, pattern:&nbsp;I) -&gt;&nbsp;Bool</font></div></blockquote><div class=""><br class=""></div><div class="">I would not change from `~=` to `=~` though.</div><div class=""><br class=""></div><div class="">So you have this:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><font face="Menlo" class="">let&nbsp;x =&nbsp;4</font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class="">switch&nbsp;x&nbsp;{</font></div><div class=""><font face="Menlo" class="">case&nbsp;let&nbsp;v&nbsp;where&nbsp;x&nbsp;~=&nbsp;0...5:&nbsp;print("matched:&nbsp;\(v)")</font></div><div class=""><font face="Menlo" class="">default:&nbsp;print("nothing!!")</font></div><div class=""><font face="Menlo" class="">}</font></div></blockquote><div class=""><br class=""></div><div class="">-David</div><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Apr 7, 2016, at 4:57 AM, David Rodrigues via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div style="font-size:12.8px" class="">Hi all,</div><div style="font-size:12.8px" class=""><br class=""></div><div style="font-size:12.8px" class="">Swift has a pattern match operator, ~=, which is unknown to many (like me until a few weeks ago), that performs a match between a value and a certain pattern, e.g. checking if an integer value is contained in a range of integers.</div><div style="font-size:12.8px" class=""><br class=""></div><div style="font-size:12.8px" class="">This operator may be little known, but it plays a key role in the language since it's used behind the scenes to support expression patterns in `switch` statement case labels, which we all know are extremely popular.</div><div style="font-size:12.8px" class=""><br class=""></div><div style="font-size:12.8px" class="">let point = (2, 4)</div><div style="font-size:12.8px" class="">switch point {</div><div style="font-size:12.8px" class="">case (0, 0):</div><div style="font-size:12.8px" class="">&nbsp; &nbsp; print("The point is at the origin")</div><div style="font-size:12.8px" class="">case (0...4, 0...4):</div><div style="font-size:12.8px" class="">&nbsp; &nbsp; print("The point is in the subregion")</div><div style="font-size:12.8px" class="">default:</div><div style="font-size:12.8px" class="">&nbsp; &nbsp; break</div><div style="font-size:12.8px" class="">}</div><div style="font-size:12.8px" class=""><br class=""></div><div style="font-size:12.8px" class="">Most of the time we don't use the operator directly but it is available and can be handy in certain conditions.</div><div style="font-size:12.8px" class=""><br class=""></div><div style="font-size:12.8px" class="">let point = (2, 4)</div><div style="font-size:12.8px" class="">switch point {</div><div style="font-size:12.8px" class="">case (let x, let y) where 0...4 ~= x &amp;&amp; 0...4 ~= y:</div><div style="font-size:12.8px" class="">&nbsp; &nbsp; print("The point is in the subregion")</div><div style="font-size:12.8px" class="">default:</div><div style="font-size:12.8px" class="">&nbsp; &nbsp; break</div><div style="font-size:12.8px" class="">}</div><div style="font-size:12.8px" class=""><br class=""></div><div style="font-size:12.8px" class="">However the current syntax is not ideal (in my opinion). We're not really declaring the operation that we want to do, and that has an impact in the expressivity and readability of the code. Currently we're doing matches like "if blue is the ocean" instead of "if the ocean is blue" or "if the ocean contains the whale" instead of "if the whale is in the ocean".</div><div style="font-size:12.8px" class=""><br class=""></div><div style="font-size:12.8px" class="">For that reason, I would like to suggest inverting the order of the operator to match more closely our logical thought.</div><div style="font-size:12.8px" class=""><br class=""></div><div style="font-size:12.8px" class="">case (let x, let y) where x =~ 0...4 &amp;&amp; y =~ 0...4: // Proposed</div><div style="font-size:12.8px" class="">// vs</div><div style="font-size:12.8px" class="">case (let x, let y) where 0...4 ~= x &amp;&amp; 0...4 ~= y: // Current</div><div style="font-size:12.8px" class=""><br class=""></div><div style="font-size:12.8px" class="">I have an ongoing proposal to suggest this change and it contains a little more context. It is available here:&nbsp;</div><div style="font-size:12.8px" class=""><br class=""></div><div style="font-size:12.8px" class=""><a href="https://github.com/dmcrodrigues/swift-evolution/blob/proposal/invert-order-of-pattern-match-operator/proposals/NNNN-invert-order-of-pattern-match-operator.md" target="_blank" class="">https://github.com/dmcrodrigues/swift-evolution/blob/proposal/invert-order-of-pattern-match-operator/proposals/NNNN-invert-order-of-pattern-match-operator.md</a>.</div><div style="font-size:12.8px" class=""><br class=""></div><div style="font-size:12.8px" class="">Any feedback is very welcome.</div><div style="font-size:12.8px" class=""><br class=""></div><div style="font-size:12.8px" class="">Thank you.</div><div style="font-size:12.8px" class=""><br class=""></div><div style="font-size:12.8px" class="">David Rodrigues</div></div>
_______________________________________________<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" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class=""></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></body></html>