<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="">Hi Jonathan,<div class=""><br class=""></div><div class="">This is really cool. Thanks for sharing! As I responded to Chris later in the thread (and to use different words), I do agree that postfix syntax is really useful, and arguably better than prefix syntax. What I was ultimately suggesting was that if Swift only had “unary” operators, then one can freely use them in either postfix or prefix positions. Just use whatever is natural for your code. The only downside of what I was suggesting is that one cannot have *different* behavior for a given operator just based on its prefix or postfix position.</div><div class=""><br class=""></div><div class="">Cheers,</div><div class="">Dave</div><div class=""><br class=""><div class=""><div><blockquote type="cite" class=""><div class="">On Dec 6, 2015, at 10:40, Jonathan Hull &lt;<a href="mailto:jhull@gbis.com" class="">jhull@gbis.com</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=""><div class="">TL;DR: Please don’t remove custom postfix operators.</div><div class=""><br class=""></div><div class="">I actually rely on the custom postfix operators a great deal.</div><div class=""><br class=""></div><div class="">My first real swift project was to write a PEG parser where you define the grammar rules in swift itself (which allows the rules and code to be intermixed freely… which is super useful). I can call functions or execute a block upon a match.</div><div class=""><br class=""></div><div class="">The grammar uses a bunch of custom operators including several postfix ones. &nbsp;Here is a snippet of rules for a grammar which allows complex math equations (This is swift code in a rules() method)</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(209, 47, 27);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">rule</span><span style="" class="">(</span>"mathFunc"<span style="" class="">)&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">&lt;-</span><span style="" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">word</span><span style="" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">&amp;</span><span style="" class=""> ( </span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">%</span>"mathFuncParams"<span style="" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">|</span><span style="" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">%</span>"mathEmptyParams"<span style="" class="">)</span></div><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(209, 47, 27);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">rule</span><span style="" class="">(</span>"mathFuncParams"<span style="" class="">)&nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">&lt;~</span><span style="" class=""> </span>"("<span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">¡</span><span style="" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">~</span><span style="" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">%</span>"mathExpr"<span style="" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">~</span><span style="" class=""> (</span>","<span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">¡</span><span style="" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">~</span><span style="" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">%</span>"mathExpr"<span style="" class="">)</span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">*</span><span style="" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">~</span><span style="" class=""> </span>")"<span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">¡</span></div><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(209, 47, 27);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">rule</span><span style="" class="">(</span>"mathEmptyParams"<span style="" class="">) </span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">&lt;~</span><span style="" class=""> </span>"("<span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">¡</span><span style="" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">~</span><span style="" class=""> </span>")"<span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">¡</span></div></div><div class=""><br class=""></div><div class="">The only reason this works at all is that there are several overloaded operators</div><div class="">&lt;-<span class="Apple-tab-span" style="white-space:pre">                </span>Define rule</div><div class="">&lt;~<span class="Apple-tab-span" style="white-space:pre">                </span>Define rule ignoring whitespace</div><div class="">&amp; &nbsp; <span class="Apple-tab-span" style="white-space:pre">                </span>Sequence</div><div class="">~ <span class="Apple-tab-span" style="white-space:pre">                </span>Same as &amp;, but ignore whitespace</div><div class="">|<span class="Apple-tab-span" style="white-space:pre">                </span>Ordered Choice</div><div class="">postfix *<span class="Apple-tab-span" style="white-space:pre">        </span>Repeat 0 or more times</div><div class="">postfix ¡<span class="Apple-tab-span" style="white-space:pre">        </span>Discard token</div><div class="">prefix %<span class="Apple-tab-span" style="white-space:pre">        </span>Reference to rule</div><div class=""><br class=""></div><div class="">As mentioned above, this is useful because I can intermix swift code and PEG rules:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(209, 47, 27);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">rule</span><span style="" class="">(</span>"boolCompare"<span style="" class="">) </span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">&lt;~</span><span style="" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">%</span>"mathExpr"<span style="" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">~</span><span style="" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">%</span>"boolCompareType"<span style="" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">~</span><span style="" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">%</span>"mathExpr"<span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">=^</span><span style="" class="">{s </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">in</span></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> rhs = s.<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">stack</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">popMath</span>()!</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> comp = s.<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">stack</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">popStr</span>()!</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> lhs = s.<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">stack</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">popMath</span>()!</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">&nbsp; &nbsp; s.<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">stack</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">push</span>(<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Token</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">boolExpr</span>(<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">ComparisonExpr</span>(lhs:lhs,rhs:rhs,comparison:comp)))</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">}</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div></div><div class="">(Above: Whenever the rhs mathExpr matches, it runs code which pops the tokens off the stack and replaces them with a token representing the comparison)</div><div class=""><br class=""></div><div class="">I have several projects which depend on this code, which I wouldn’t be able to do without custom operators (and postfix operators make it a lot closer to the standard PEG notation)</div><div class=""><br class=""></div><div class="">Please don’t remove custom postfix operators.</div><div class=""><br class=""></div><div class="">Thanks,</div><div class="">Jon</div><div class=""><br class=""></div><div class=""><br class=""></div><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Dec 5, 2015, at 11:26 AM, David Zarzycki 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 class=""><p class="">Hi Chris,</p><p class="">An observation about SE-0004: Remove the ++ and — operators:</p><p class="">Given that the above is accepted, the only remaining postfix operator in the language is ‘!’ — and that is implemented by the compiler. Please consider just removing user-defined postfix operators entirely. Doing so would define away a type checking ambiguity where “let f : T -&gt; T = someOperatorIdentifier” is ambiguous when both prefix and postfix operators exist.</p><p class="">Cheers, Dave <em class="">____________________________________________</em>_ swift-evolution mailing list <a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a> <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></p>

<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=vmG20pDvfvCvG17-2BDXZuJGkVRWrvQJh5Zv2RpdNUSQkDL64c5btrTpBtnEs35tNuQbX96E9Du41O-2B2NTIeiO-2FmXQC2yQyhy-2Fpq2jWeBshwkFzjPul-2BeGQXoBaCQkMt06J-2B5R08StrcX-2F9-2FpP0RPJq3fxN3wGTGGWScUmgEO178WjsXd0SOf7G2sf50MCiZzghIssuu3KXEpz7MW5Shpf1w-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>
</div></blockquote></div><br class=""></div></div></blockquote></div><br class=""></div></div></body></html>