lua-users home
lua-l archive

Re: Ternary operator patch

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 2010年9月16日, David Given wrote:
>
> But what's the issue with & and |? & has a higher priority than |, which
> is what I'd expect (boolean multiply vs boolean add).
The problem is their precedence relative to the comparison operators.
 if (a & 15 == 0) fail();
In a better world C's precedence table would be:
 () [] -> . ++ -- left to right
 - ! ~ ++ -- * & (type) sizeof right to left
 * / % & << >> left to right
 + - ^ | left to right
 < <= > >= == != left to right
 && left to right
 || left to right
 ?: right to left
 = += -= *= /= %= <<= >>= &= ^= |= right to left
 , left to right
Even better would be to replace prefix * with postfix ^ (like Pascal)
which would fix the tortured declaration syntax. Postfix ^ can be optional
before . just like it is before () and [], so you can abolish ->. Infix ^
would need to be spelled differently to avoid a clash; ~ would make sense
by analogy with -. It should also be possible to chain comparison
operators like BCPL and Python. Then you would get:
 () [] ^ . ++ -- left to right
 - ! ~ ++ -- & (type) sizeof right to left
 * / % & << >> left to right
 + - ~ | left to right
 < <= > >= == != chained
 && left to right
 || left to right
 ?: right to left
 = += -= *= /= %= <<= >>= &= ^= |= right to left
 , left to right
Tony.
-- 
f.anthony.n.finch <dot@dotat.at> http://dotat.at/
HUMBER THAMES DOVER WIGHT PORTLAND: NORTH BACKING WEST OR NORTHWEST, 5 TO 7,
DECREASING 4 OR 5, OCCASIONALLY 6 LATER IN HUMBER AND THAMES. MODERATE OR
ROUGH. RAIN THEN FAIR. GOOD.

AltStyle によって変換されたページ (->オリジナル) /