<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=""><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=""><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 Nov 16, 2016, at 10:47 AM, David Sweeris 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=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class=""><br class="Apple-interchange-newline">On Nov 16, 2016, at 9:25 AM, Karl via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><br class=""><br class=""><blockquote type="cite" class="">On 14 Nov 2016, at 12:48, Haravikk via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><br class="">I'm a +1 on the feature, though for simply handling symmetry it's not a super critical issue.<br class=""><br class=""><br class="">I wonder though, when you start looking at symmetry is it worth looking at other patterns? For example, could symmetrical operators be covered by a broader multi-part operator definition?<br class=""><br class="">I was thinking recently it would be convenient if I could define say a 3-dimensional point like so: &lt;x, y, z&gt;<br class=""><br class="">In this case you're looking at a symmetric operator with two different components (opening and closing angle brackets) with the ability to take three arguments. Is there a way we could define and implement something along these lines? If so it would be very flexible, and potential allow us to unify all operators into a single format.<br class=""><br class="">For example, you can thing of a prefix operator as being a leading symbol plus one argument, while a postfix is one argument plus a trailing symbol, a binary operator is an argument, a symbol and another argument, a symmetric operator is a leading symbol, an argument and a trailing symbol (doesn't have to be identical).<br class=""><br class="">If we had a means of specifying operators in this way (as a complete pattern) we could do away with special cases of operators entirely, though they may be worth keeping for compatibility and as a shorthand.<br class=""><br class=""><blockquote type="cite" class="">On 14 Nov 2016, at 09:57, Dimitri Racordon via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><br class="">+1<br class=""><br class="">I think the use cases are not that sparse actually.<br class="">I would also argue that it would be easier to understand the intent of the code with some sort of keyword than with a hard copy of each function.<br class=""><br class=""><br class=""><br class=""><blockquote type="cite" class="">On 14 Nov 2016, at 10:51, Anton Zhilin via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><br class="">-1<br class="">Not worth adding syntactic sugar for a narrow use case. Plus it's an additive feature.<br class="">_______________________________________________<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=""></blockquote><br class="">_______________________________________________<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=""></blockquote><br class="">_______________________________________________<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=""></blockquote><br class=""><br class="">Commutative operators are very common and I would definitely +1 a shorthand for them.<br class=""><br class="">You seem to be talking about a custom literal, rather than an operator - you said you want to “define” a point with some special syntax. Try ArrayLiteralConvertible.<br class=""></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">The problem is there’s no way to conform to ArrayLiteralConvertible only when a certain # of elements are present, and the protocol requires the init function to not be failable. In this particular case you can fake it by only copying the first 3 values from the array and using 0 to fill in missing elements. It could be argued that filling in the 0s is “correct enough”, but throwing out extra elements is certainly bad. And you’re still in the (undesirable, IMHO) position of using run-time checks to account for what amounts to a syntax error that should be easy to catch at compile-time.</span></div></blockquote><br class=""></div><div class="">You can make it a precondition that the array have the right number of elements; this is what the simd module types on Apple platforms do, for example:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>1&gt; import simd</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>2&gt; let w = [1,2,3,4] as float3</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>fatal error: float3 requires a three-element array</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">but you're still left with a run-time error rather than a syntax-error, which is definitely not ideal.</span></div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><br class=""></span></div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">– Steve</span></div></div><br class=""></div></div></body></html>