lua-users home
lua-l archive

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

On Wed, Aug 14, 2019 at 9:32 PM Oliver wrote:
I would
prefer simple +=. I know from time to time this comes up in this list but I
never understood why Lua does not have +=.

Problem #1
+= could not be added alone.
There are a lot of similar operators:
Should new metamethods be introduced?
PRO: they would be useful for DSLs
CON: too many metamethods to implement in regular user classes.
Problem #2
I guess XOR is the second popular operator (after addition) used in such short notation.
But we can't introduce short notation for XOR "a = a ~ b", because "~=" is already used for non-equality.
"^=" in Lua would be raising to the power, not XOR
Problem #3
Why only right addition/multiplication/division/etc?
"a *= b" means "a = a * b", but how to write "a = b * a"?
This might be important, for example, for matrices.