Re:Better Operator Precedence
by daniellehmann on Sunday October 31, 2021 @10:27AM
(#29057205)
I don't know Swift, but does this mean there are expressions in Swift where the compiler returns an error, because the expression is ambiguous without additional parentheses?
(My understanding of the article is that it mainly argues for _partial_ precedence, not so much that precedence/associativity can be defined in the program - the latter is also the case in other languages, e.g., Haskell.)
Re:Better Operator Precedence
by superlopuh on Sunday October 31, 2021 @11:01AM
(#29057446)
Yes:
precedencegroup MyPrecedence {}
infix operator +++: MyPrecedence
func +++ (lhs: Int, rhs: Int) -> Int { lhs + rhs }
let a = 1 + 2 +++ 3
Error: Adjacent operators are in unordered precedence groups 'AdditionPrecedence' and 'MyPrecedence'
Re:Better Operator Precedence
by daniellehmann on Sunday October 31, 2021 @11:07AM
(#29057501)
Very cool, thanks a lot for the example!
https://github.com/apple/swift/blob/3ea9e9e55281b9957d2b5486...