I disagree. The binary operators have properties that are comparable to 
arithmetic operators, and their precedence is easy to define as such. & has 
multiplication-like properties (0*0=0, 0*1=0, 1*0=0, 1*1=1); | has 
addition-like properties (0+0=0, 0+1=1, 1+0=1, 1+1=2); ^ has subtraction-like 
properties (0-0=0, 0-1=-1, 1-0=1, 1-1=0), and their precedences are set 
accordingly (& is multiplicative, | and ^ are additive).

The same applies to && and ||. Bit shifts are exponentiative.

Binary operators get especially confusing in some languages because their 
precedence is lower than comparison operators. For instance, in C, `a & b == c` 
gets parsed as `a & (b == c)`. In Swift, the precedence of binary operators is 
above that of comparison operators, so we don't have that problem.

Félix

> Le 1 août 2016 à 20:48:21, Rob Mayoff via swift-evolution 
> <[email protected]> a écrit :
> 
>>> 1 | 2 ^ 3   // or this?
>> 
>> 
>> No. Both of those are bitwise operations. They are often used together. They
>> have a refined relative precedence in Swift that makes sense.
> 
> I have no idea what the relative precedence of those operators is in
> Swift, C, or any other language, and thinking about it now, no
> relative precedence seems sensible or obvious to me. Those operators
> (and bitwise-&) are excellent examples of operators that should
> require parentheses.
> _______________________________________________
> swift-evolution mailing list
> [email protected]
> https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to