<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Wed, May 18, 2016 at 12:10 AM Brent Royal-Gordon via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">> Or should the compiler only allow those two argument labels for unary operator functions? That feels strange since it's not a restriction present anywhere else, and it starts to feel like the labels have a dual purpose that also falls into the realm of keywords.<br>
<br>
A similar restriction exists on operators currently. Today, Swift does not allow keywords on operator parameters:<br>
<br>
23> prefix func !<T>(prefix value: T) {}<br>
repl.swift:23:18: error: operator cannot have keyword arguments<br>
prefix func !<T>(prefix value: T) {}<br>
^~~~~~~<br>
<br>
What I'm suggesting is that, on unary operators, Swift require either the keyword "prefix" or "postfix" on the argument, and use that to differentiate between prefix and postfix operators. No other keyword would be used or permitted, and no keyword would be used or permitted on infix operators' arguments.<br></blockquote><div><br></div></div><div dir="ltr"><div class="gmail_quote"><div>I would be supportive of this. The syntax for static prefix/postfix operators in that proposal was a matter of some earlier debate (in e-mail threads, and a couple comments in the pull request <<a href="https://github.com/apple/swift-evolution/pull/283">https://github.com/apple/swift-evolution/pull/283</a>>) and was one of the parts of the proposal I thought felt less natural.</div><div><br></div><div>I think we should definitely have a solution that avoids duplication (so not having a `prefix` as a leading keyword and as an argument label). Since prefix/postfix operators are required to only have one argument, and those arguments must already not have labels, introducing prefix/postfix as labels instead of keywords to distinguish them seems natural.</div><div><br></div><div>The other major benefit (which I mention in a PR comment above) is that, if you have a prefix and postfix operator with the same name, there is no way currently to get function references to both of them (for passing to other algorithms), because there are no labels used to distinguish them. For example, if you use `++` as a function reference (ignoring the fact that it's deprecated), the REPL takes the last one that was defined. (I didn't test what the compiler does, but presumably it's arbitrary depending on the ordering of the data structures used to store those operators.) Using argument labels would solve this problem as well.</div></div></div><div dir="ltr"><div class="gmail_quote"><div><br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
--<br>
Brent Royal-Gordon<br>
Architechies<br>
<br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div></div></div>