lua-users home
lua-l archive

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


On Fri, Jan 8, 2021 at 9:41 PM Roberto Ierusalimschy wrote:
exponentiation: in Lua, it follows the usual mathematic rules


BTW, this is my top 3 pitfalls of Lua precedence rules (in the order of decreasing surprise):
#str^2    is not  (#str)^2
-x%2-x%3  is not  -x%3-x%2
1<<n-1    is not  (1<<n)-1


I assume that the following rules are well known and don't need parentheses:
Arithmetic (bar exponentiation) and concatentation operations between
them.


"Arithmetic with concatenation between them" is intuitively clear.
But I can't wrap my head around concatenation vs bitwise precedence.
"message..x+7" is OK, but "message..x&7" is not OK
What use cases did you have in mind?