lua-users home
lua-l archive

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


>   Folks,
>   Greetings. This is my first post to the Lua list.
>   I've searched for an answer to this question without
>   any luck.
>   Why is assignment a statement in Lua, rather than an
>   operator?
>   ~~ Paul

Before we get into the inherent problems of this question, I think it's useful to point out the simplest response: Simplicity.

Lua has often taken the approach of simplicity over abundance of choices. Lua is a very powerful language, but you will still notice it lacks operators which may be common in other places, such as += or bitwise operations. On that note, why ask for such a case when something like:

foo = a + b;
if(foo == 0)

Would compile to the same bytecode as 

if(0 == (foo = a+b))

Now, on that note, we find some other peculiarities to Lua which are not present in other languages. C does not have a syntax similar to the following:

a,b,c = 1,2,3;

Having said that, what is the result of the following?

print(a,b = true,nil)


Given that you gain nothing except a few less characters in source code, and increase complexity of both the parser and readability, I don't see a valid case for asking for it.

Hope that helps,
-- Matthew P. Del Buono