[swift-evolution] [Proposal] Change infix operator attributes syntax to be more consistent with the rest of the language

Jean-Daniel Dupas mailing at xenonium.com
Sun Mar 6 08:33:39 CST 2016


> Le 6 mars 2016 à 12:44, Brent Royal-Gordon via swift-evolution <swift-evolution at swift.org> a écrit :
> 
>> First of all, I suggest that we remove `assignment` from Swift 2.2 in any case. It has been deprecated for long enough.
>> 
>> Operator declarations are always global.
>> Operator declarations of the same operator are always in conflict, even if in different modules.
>> Therefore, I believe, operators would be best defined using directive syntax:
>> 
>> #operator(<>, fixity: infix, associativity: left, precedence: 100)
>> #operator(!, fixity: postfix)
>> 
>> It's obvious from this declaration that it must be global and must not be duplicated even in different modules (remember C macros?).
>> It would allow us to remove operator declaration grammar entirely, add a directive instead. Simplification of grammar and consistency is one of directions for Swift 2.2 and Swift 3.0.
>> 
>> Why not curly braces? Curly braces in Swift declarations are used to declare multiple "child" entities. On the other hand, attributes and directives are used with *preudo-arguments*.
>> I also want to remind the main difference between attributes and directives in Swift. @-attributes always stand before something and modify it. #-directives are stand-alone things on themselves.
> 
> Treating it as a compiler directive is an interesting idea. It certainly doesn't work anything like other declarations in Swift; a compiler directive might drive that point home.
> 
> I don't really like this specific design, though—it doesn't really match the look and feel of existing directives. Looking through the Swift book, I believe the only compiler directive that actually *changes* anything is `#setline` (The Directive Formerly Known As `#line`). Its parameters consist of an unmarked list of values with no separator or labeling. Trying to duplicate that style would give us something like this:

As describe in the #setline change proposition, #setline is a tool generated directive used only by the compiler. No time has been waste to try to design it to be ‘swift like’ or readable, or anything else, and so I don’t think we should use it as an example in any design discussion.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160306/c0293727/attachment.html>


More information about the swift-evolution mailing list