lua-users home
lua-l archive

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

Ross Andrews wrote:
> By "order of assignment is undefined", does it mean that the order in which
> values are put in variables is undefined, or the order in which the
> right-hand side is evaluated is undefined?

Actually both. The parallel assignment statement only guarantees
that all expressions on the right-hand side are evaluated *before*
any of the assignments are made. See section 2.4.3 in the Lua 5.1

But it neither guarantees a particular *evaluation order* for the
right-hand side, nor a particular *assignment order* for the
left-hand side.

More than you ever wanted to know about this topic can be found
in my message that triggered the clarification from Roberto:

> Which means that this:
> os.execute_without_echo, os.execute = os.execute, os.execute_with_echo
> Will either work or not, arbitrarily (it does seem to work in 5.1.4).

It always works, because the expression results of the right-hand
side are stored in temporaries before doing the assignment.

[Actually, the Lua parser avoids the temporaries if it finds no
conflict between the two sides. It doesn't do that for your
example, of course.]