<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On Feb 17, 2017, at 10:51 AM, Xiaodi Wu <<a href="mailto:xiaodi.wu@gmail.com" class="">xiaodi.wu@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><br class=""><div class="gmail_extra"><div class="gmail_quote">On Fri, Feb 17, 2017 at 12:46 PM, David Sweeris <span dir="ltr" class=""><<a href="mailto:davesweeris@mac.com" target="_blank" class="">davesweeris@mac.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><span class=""><br class=""><blockquote type="cite" class="">On Feb 17, 2017, at 10:38 AM, Abe Schneider via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>> wrote:<br class=""><br class="">If I read Nicolas's post correctly, I think he's more arguing for the<br class="">ability to create syntax that allows Swift to behave in a similar way<br class="">to Numpy/Matlab. While Swift already does allow you to define your own<br class="">operators, the main complaint is that he can't define the specific<br class="">operators he would like.</blockquote><br class=""></span><div class="">In Xcode 8.2.1, with the 8.2.1 toolchain, this works (well, it compiles… obviously it doesn’t check for mis-matched array lengths):</div><div class=""><div style="margin:0px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">infix</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures:no-common-ligatures" class="">operator</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> .+</span></div><div style="margin:0px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures;color:#bb2ca2" class="">func</span><span style="font-variant-ligatures:no-common-ligatures" class=""> .+ <T: </span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa" class="">Integer</span><span style="font-variant-ligatures:no-common-ligatures" class="">> (lhs: [</span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187" class="">T</span><span style="font-variant-ligatures:no-common-ligatures" class="">], rhs: [</span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187" class="">T</span><span style="font-variant-ligatures:no-common-ligatures" class="">]) -> [</span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187" class="">T</span><span style="font-variant-ligatures:no-common-ligatures" class="">] {</span></div></div></div></blockquote><div class=""><br class=""></div><div class="">precondition(lhs.count == rhs.count)</div><div class=""> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><div class=""><div style="margin:0px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:#bb2ca2" class="">return</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:#3d1d81" class="">zip</span><span style="font-variant-ligatures:no-common-ligatures" class="">(lhs, rhs).</span><span style="font-variant-ligatures:no-common-ligatures;color:#3d1d81" class="">map</span><span style="font-variant-ligatures:no-common-ligatures" class=""> { $0.</span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8" class="">0</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:#3d1d81" class="">+</span><span style="font-variant-ligatures:no-common-ligatures" class=""> $0.</span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8" class="">1</span><span style="font-variant-ligatures:no-common-ligatures" class=""> }</span></div><div style="margin:0px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">}</span></div></div><div class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><div style="margin:0px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)" class=""><span style="font-variant-ligatures:no-common-ligatures;color:#3d1d81" class="">print</span><span style="font-variant-ligatures: no-common-ligatures;" class="">([</span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8" class="">1</span><span style="font-variant-ligatures: no-common-ligatures;" class="">,</span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8" class="">2</span><span style="font-variant-ligatures: no-common-ligatures;" class="">,</span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8" class="">3</span><span style="font-variant-ligatures: no-common-ligatures;" class="">]</span><span style="font-variant-ligatures:no-common-ligatures;color:#31595d" class="">.+</span><span style="font-variant-ligatures: no-common-ligatures;" class="">[</span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8" class="">4</span><span style="font-variant-ligatures: no-common-ligatures;" class="">,</span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8" class="">5</span><span style="font-variant-ligatures: no-common-ligatures;" class="">,</span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8" class="">6</span><span style="font-variant-ligatures: no-common-ligatures;" class="">]) </span><span style="font-variant-ligatures:no-common-ligatures" class="">//outputs [5, 7, 9]</span></div></span></div></div></blockquote><div class=""><br class=""></div><div class="">There's nothing, afaik, which stands in the way of that syntax today.</div></div></div></div></div></blockquote><div>Yep, that’s what I was demonstrating</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class="">The proposal is to extend the standard library to add syntax for a math library. The idea of having a core math library has already been mentioned on this list, to great approval, but it should come in the form of an actual library, and not a syntax only!</div></div></div></div></div></blockquote><br class=""></div><div>Oh, sorry, I was confused… I thought the proposal was to allow the syntax.</div><div><br class=""></div><div>Well, count me as another +1 for adding a `CoreMath` library (although it should probably be called something else, unless we can make it work in Obj-C, too).</div><div><br class=""></div><div>- Dave Sweeris</div></body></html>