<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="">Maybe this wan't the original idea but I have a proposition that is both parseable and useful<div class=""><br class=""></div><div class="">Imagine you have this struct</div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">struct</span> Person {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> name: <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">String</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> age: <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">and you want to use an operator to compare their fields because you do that often.</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">Typically you would do something along those lines:</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> &lt;(lhs: <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Person</span>, rhs: <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Person</span>) -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Bool</span> {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span> lhs.<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">age</span> &lt; rhs.<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">age</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> &lt;&lt;(lhs: <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Person</span>, rhs: <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Person</span>) -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Bool</span> {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span> lhs.<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">name</span> &lt; rhs.<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">name</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">and then use it like so</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> john = <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Person</span>(name: <span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"John"</span>, age: <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">12</span>)</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> steve = <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Person</span>(name: <span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"Steve"</span>, age: <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">14</span>)</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135);" class="">john<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">&lt;</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span>steve</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135);" class="">john<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">&lt;&lt;</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span>steve</div></div><div class=""><br class=""></div><div class="">The point isn't that "&lt;" and "&lt;&lt;" are bad operators for this purpose but that operators quickly become confusing when abused.</div><div class="">I think one great solution would be to allow alphanumeric character after the operator head like so:&nbsp;</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: rgb(187, 44, 162);" class="">func</span> &lt;age(lhs: <span style="color: rgb(79, 129, 135);" class="">Person</span>, rhs: <span style="color: rgb(79, 129, 135);" class="">Person</span>) -&gt; Bool {…}</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="color: rgb(187, 44, 162);" class="">func</span>&nbsp;&lt;name(lhs: <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Person</span>, rhs: <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Person</span>) -&gt; Bool {…}</div></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><div style="margin: 0px; line-height: normal; color: rgb(79, 129, 135);" class="">john<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">&lt;</span><span style="color: rgb(0, 0, 0);" class="">age&nbsp;</span>steve</div><div style="margin: 0px; line-height: normal; color: rgb(79, 129, 135);" class="">john<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">&lt;</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">name&nbsp;</span>steve</div></div><div class=""><br class=""></div><div class="">and the grammar would need to be changed to:</div><div class=""><br class=""></div><div class="">operator -&gt; operator-head operator-characters</div><div class="">operator-characters -&gt; operator-characters operator-tail</div><div class="">operator-tail -&gt; operator-characters</div><div class="">operator-tail -&gt; alphanumeric alphanumeric?</div><div class=""><br class=""></div><div class="">or something similar</div><div class=""><br class=""></div><div class="">Extra:</div><div class="">If we extend this idea further we could even imagine nice operators like</div><div class=""><br class=""></div><div class=""><div style="font-family: Menlo; font-size: 11px; margin: 0px; line-height: normal; color: rgb(79, 129, 135);" class="">john<span style="color: rgb(0, 0, 0);" class="">&nbsp;</span><span style="color: rgb(49, 89, 93);" class="">&lt;⎮</span><span style="color: rgb(0, 0, 0);" class="">age⎮&nbsp;</span>steve</div><div style="font-family: Menlo; font-size: 11px; margin: 0px; line-height: normal;" class=""><font color="#4f8187" class="">john</font><span style="color: rgb(0, 0, 0);" class="">&nbsp;</span><font color="#31595d" class="">&gt;⎮</font><span style="color: rgb(0, 0, 0);" class="">name⎮&nbsp;</span><font color="#4f8187" class="">steve</font></div></div><div class=""><br class=""></div><div class="">And I will argue that this is more both readable and desirable than john.compareAge(steve) or john.lessThanAge(steve) even though that's what it years of Obj-C and OOP tells us to do.</div><div class=""><br class=""></div><div class=""><div><blockquote type="cite" class=""><div class="">On 10 Jan 2016, at 02:23, Chris Lattner 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=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Jan 9, 2016, at 11:56 AM, Dennis Lysenko &lt;<a href="mailto:dennis.s.lysenko@gmail.com" class="">dennis.s.lysenko@gmail.com</a>&gt; wrote:</div><div class=""><p dir="ltr" class="">Chris, hmm... Can you really say that this is the only problem that would warrant infix functions? To say what you just seemingly implies that you believe the use cases outlined here are the only reason one would want infix operators, and that the use cases outlined here don't warrant infix functions. </p><p dir="ltr" class="">I'm sure there are plenty more reasons for implementing infix functions and I think it would be reactionary to effectively discourage their consideration on the basis of one tangentially related email chain. </p></div></blockquote><div class="">I’m saying that I cannot personally imagine a use-case compelling enough to make the language more complicated for (including the ones listed on the thread). &nbsp;If you can, please share them and we can discuss it.</div><div class=""><br class=""></div><div class="">-Chris</div></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=41N46VivWCZSszJfIBo5Gp-2B3i74lSY31hqGrt-2BWAHhlv3xseknoO6C31nVXBr2N6PIdF-2Bfdb9oPQBySN4pBPAg4-2F9GQJoVR-2BeXPYgAh-2BmYdn4M4KhUWrJIr8UDqGQz-2FtTx4oisAT2n6HaF4YNJtr-2BELmqwwudvl89GGUdrQbkTy7oWXIFsIyse47pgK5D5SlpBdXZMZH-2BvejxZuja8JSpw-3D-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;" 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=""></div></body></html>