lua-users home
lua-l archive

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


> > For instance, what would be the result of "f(x)[1] = 1" (assuming that
> > f(x) did not return a table)?
> 
> 
> The result will be that you create an anonymouse table value
> {1=1}. Which is what I would expect.

And then assign it to "f(x)"? That is your proposed semantics, is it
not? It not only creates a table, but assign it to the "variable" being
indexed.

In Lua, "a[1]=1" does not refer to the variable 'a', but to the
expression 'a'; what matters is only the _value_ of 'a'. That semantics
enables things like "f(x)[1] = 1" without tricks. If 'a' means a
variable (so that you can asign values to it), then other expressions
(such as "f(x)") either have strange behavior or need special treatment.

-- Roberto