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

Developer devteam.codafi at gmail.com
Sat Mar 5 23:21:00 CST 2016


I think there's something to this, but I'd prefer it look a bit more like what happened in SE-40 (https://github.com/apple/swift-evolution/blob/714dd43863775705cebc77574287ab0974bfa615/proposals/0040-attributecolons.md) so 'associativity' and 'precedence' are made to look more compiler-construct-y.

infix operator <> { 
  @associativity(left)
  @precedence(100)
}

As for assignment operators, if memory serves syntax for them was quickly deprecated because they can be subsumed by making the LHS of an infix operator inout.  I'm not sure there needs to be much more at the declaration site than that.

~Robert Widmann

2016/03/05 21:54、Kevin Lundberg via swift-evolution <swift-evolution at swift.org> のメッセージ:

> Ever since Swift 1.0 I've found the infix operator attribute syntax strange:
> 
> infix operator <> { associativity left precedence 100 }
> 
> The value of the attribute has no visual cue that ties it to the name of
> the attribute. One could arguably read left as its own attribute name
> rather than the value set to the associativity attribute, or could read
> the wrong pair as one attribute, like "left precedence".
> 
> In the spirit of Erica Sadun's recent proposal to make attribute syntax
> uniform by using : over =, I'd like to see operator declaration syntax
> follow a similar structure:
> 
> infix operator <> { associativity: left, precedence: 100 }
> 
> In my opinion, this simple change makes operator attributes much more
> readable. This also should help future proof readability in operator
> attributes if operators gain more of them in the future. A longer list
> of attributes with the current syntax would become much harder to read.
> 
> The only (minor) sticking point I've noticed is the assignment attribute
> in the standard library:
> https://github.com/apple/swift/blob/12b793c87f160a0f18bb8762e425174205c5d80a/stdlib/public/core/Policy.swift#L427.
> This attribute isn't documented in TSPL and it has no value associated
> with it. Since user-defined operators are not meant to be assignment
> operators, it may not matter much how these are represented, but
> ostensibly some user-defined attribute that has no value may come about
> in the future. We could make these attributes simply look like this:
> 
> infixoperator+={ associativity:right,precedence: 90,assignment }
> 
> or perhaps we could make it so that this attribute must now have a
> Boolean value that defaults to false if it isn't provided:
> 
> infixoperator+={ associativity:right,precedence: 90,assignment: true }
> 
> Any thoughts?
> 
> - Kevin
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160305/43c5c7ea/attachment.html>


More information about the swift-evolution mailing list