[swift-evolution] Feedback for SE-0004: Remove the ++ and -- operators

David Zarzycki zarzycki at icloud.com
Sun Dec 6 08:22:49 CST 2015


> On Dec 6, 2015, at 00:04, Chris Lattner <clattner at apple.com> wrote:
> 
> 
>> On Dec 5, 2015, at 11:26 AM, David Zarzycki <zarzycki at icloud.com> wrote:
>> 
>> Hi Chris,
>> 
>> An observation about SE-0004: Remove the ++ and — operators:
>> 
>> 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.
> 
> Hi Dave!
> 
> That is definitely an interesting idea.  In practice, we won’t be able to remove ++/— from the compiler until the ~Spring 2017 release, since Swift 3 will want to parse the old code and reject it with a fixit hint. 
> 
>> Doing so would define away a type checking ambiguity where “let f = T -> T = someOperatorIdentifier” is ambiguous when both prefix and postfix operators exist.
> 
> Besides the general simplification potential for the language, is this a theoretical concern or an actual one?  You can currently do something like “let f = T->T = {$0^}” or “{^$0}” to disambiguate the prefix/postfix forms.

It is just simplification that opens the door to further simplicity and self-consistency within the language. In addition to not needing the above workaround, one could remove the fixity keywords/attributes altogether, because they’d be inferable from context.

If one wants to go deep down the rabbit hole, one could let developers avoid nested parenthesis and the “spiral call syntax problem” by allowing the language to use the same unary operator in either prefix or postfix positions. For example, instead of “(^(-(~x).a).b).c”, one could write “x~.a-.b^.c” to accomplish the same goal.

Dave


More information about the swift-evolution mailing list