<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div></div><div>David, what about un-labeled parameters? If a function has 2 parameters of the same type, how does compiler know which ones's which?</div><div><br>On Nov 13, 2016, at 9:49 PM, David Sweeris via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html charset=utf-8"><br class=""><div><blockquote type="cite" class=""><div class="">On Nov 13, 2016, at 1:38 PM, Андрей Володин 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="">Hi, list!<div class=""><br class=""></div><div class="">I’m thinking about proposal that would add a possibility to save some time on creating symmetrical binary operators.</div><div class=""><br class=""></div><div class="">The latest code example from my math lib:</div><div class=""><br class=""><div class=""><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: 'Fira Code';" class=""><span style="color: rgb(231, 232, 235); font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures;" class="">@inline(__always)</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures;" class="">public</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures;" class="">static</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures;" class="">func</span><span style="font-variant-ligatures: no-common-ligatures" class=""> *(lhs: </span><span style="font-variant-ligatures: no-common-ligatures;" class="">Angle</span><span style="font-variant-ligatures: no-common-ligatures" class="">, rhs: </span><span style="font-variant-ligatures: no-common-ligatures;" class="">Float</span><span style="font-variant-ligatures: no-common-ligatures" class="">) -&gt; </span><span style="font-variant-ligatures: no-common-ligatures;" class="">Angle</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures;" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures;" class="">Angle</span><span style="font-variant-ligatures: no-common-ligatures" class="">(lhs.</span><span style="font-variant-ligatures: no-common-ligatures;" class="">degrees</span><span style="font-variant-ligatures: no-common-ligatures" class=""> * rhs)</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: 'Fira Code'; min-height: 17px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp;&nbsp; &nbsp;</span><br class="webkit-block-placeholder"></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures" class="">@inline(__always)</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures;" class="">public</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures;" class="">static</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures;" class="">func</span><span style="font-variant-ligatures: no-common-ligatures" class=""> *(lhs: </span><span style="font-variant-ligatures: no-common-ligatures;" class="">Float</span><span style="font-variant-ligatures: no-common-ligatures" class="">, rhs: </span><span style="font-variant-ligatures: no-common-ligatures;" class="">Angle</span><span style="font-variant-ligatures: no-common-ligatures" class="">) -&gt; </span><span style="font-variant-ligatures: no-common-ligatures;" class="">Angle</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures;" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures;" class="">Angle</span><span style="font-variant-ligatures: no-common-ligatures" class="">(rhs.</span><span style="font-variant-ligatures: no-common-ligatures;" class="">degrees</span><span style="font-variant-ligatures: no-common-ligatures" class=""> * lhs)</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; }</span></div></div></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: 'Fira Code'; color: rgb(231, 232, 235);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div style="margin: 0px; line-height: normal;" class="">The API of Angle doesn’t really matter here, what’s important is that I have to write another operator to make it symmetrical. Not so hard: 3 lines of code. It can even refer to original implementation, instead of duplicating the logic. But I think it would be nice to have something like symmetrical keyword, just like we have associativity and precedence.&nbsp;</div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">I also bet that all operators should be asymmetrical by default.</div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">Any thoughts?</div></div></div></blockquote><div><br class=""></div>I fully support adding a “@commutative” attribute or something to let the compiler know that a function can be called with its arguments out of order, but I’m thoroughly against turning it on by default. Some operations, such as matrix multiplication, aren’t even defined if you swap the arguments.</div><div><br class=""></div><div>- Dave Sweeris</div></div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></body></html>