lua-users home
lua-l archive

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

Eike Decker wrote:
> I am carrying this in my mind for some time now and I guess, I am not
> alone: 
> What about a few new operators?
> I think most people with a C/C++ background are missing the += *= etc
> operators - and in my opinion these are really useful.
> [...]
> Are there any reasons that speak against such operators (btw., the #
> operator is was a great addition to 5.1)? 

Here are some very personnal reasons:

1) In Lua, contrary to C/C++, assignments are statements but not
expressions. C++ syntax relies heavily on the fact that assignations are
expressions. In Lua you have a single assignment operator, just one,
which is not in the same category at all than binary operators (+ - * /
% .. and or). So adding new assignments operators means:
 - having several assignment operators instead of just one (and going
from 1 to 2+ is much more difficult than going from n to n+1)
 - introducing ambiguity between assignment and expressions (because +=
does both)
 - introducing += will encorage people to ask for ++, both prefixed and
suffixed, and ++ will encourage people to ask for assignments to become
expressions, which will completely change the syntax and semantics of

2) It also makes it much easier to overide the semantics without
thinking to all corner cases introduced (C++ const-ness and copy
constructor mechanism are in part consequences of the ambiguity
mentionned above).

3) The very fact that expressions and statements are distinct things in
Lua makes the language much easier to teach to non-programmers, which
constitute a non-marginal part of Lua users.

I don't know which are the official reasons. The recurrence of that
topic definitively means that we need some online list of frequently
asked and rejected Lua heavy modifications.