[swift-evolution] Proposal: change infix operator attributes syntax to be more consistent with the rest of the language
Kevin Lundberg
kevin at klundberg.com
Mon Mar 7 19:41:35 CST 2016
If you think of modelling operator behavior representations like an
enum, then fixity naturally feels different compared to the other
behavioral parameters:
enum OpBehavior {
case prefix
case postfix
case infix(associativity: OpAssociativity, precedence: UInt8)
}
enum OpAssociativity { case left, right, none }
The behavioral parameters only apply to infix; making them look like
they could apply to anything by making them syntactic siblings to fixity
may lead one to think they could all be applied everywhere.
What about a modification to what Erica suggested?:
operator += infix(associativity: left, precedence: 90, assignment) //
assuming that assignment needs to stay around for now
On 3/6/2016 4:55 PM, Radosław Pietruszewski wrote:
> I agree “infix operator” reads more naturally, but I find it a bit
> strange to split operator configuration into fixity prefix and other
> parameters in curly braces/parentheses.
>
> — Radek
>
>> On 06 Mar 2016, at 20:46, Kevin Lundberg via swift-evolution
>> <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>
>> Personally I like the current way of declaring an operator's expected
>> "fixity" as it reads much more naturally:
>>
>> infix operator += // reads "an infix operator named +="
>>
>> when compared to
>>
>> operator += (infix)
>> // or
>> operator += (fixity: infix) // reads as "an operator named += which
>> has a fixity of infix"
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160307/f1b6748c/attachment.html>
More information about the swift-evolution
mailing list