lua-users home
lua-l archive

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


On Sun, May 9, 2010 at 5:40 PM, liam mail <liam.list@googlemail.com> wrote:
> I have always wanted assignment by addition operator += and company. I have
> had a look at the mailing list archive yet can not see a reason for why the
> language does not support it, can anybody shed any light?
>
> Liam
>

This may not be the main, official reason, but I think it is a factor:
making 'a++;' work as a shorter way of writing the statement 'a = a +
1;' is one thing, but for most programmers, that isn't quite enough.
Because if you have that, you'd equally expect things like 'while (a++
< 10) do ...' to work. However in Lua (unlike many other languages,
particularly ones derived from C) expressions and statements are
strictly separated. So, you can't just add a new statement and get a
new expression for free - you'd need to add "a++" the statement and
"a++" the expression, and the same for all the other mutatory
operators. You might say, "so what?" but that's a relatively weighty
addition to the language, and this is where it starts to conflict with
Lua's goal to keep the parser as light and fast as possible.

-Duncan