[prev in list] [next in list] [prev in thread] [next in thread] 

List:       lua-l
Subject:    Re: bug report: LUA compiler glitch
From:       HyperHacker <hyperhacker () gmail ! com>
Date:       2011-08-09 22:58:00
Message-ID: CA+rfA1RUcKOoQLsB0S7-FOzkrJxX0bHZedgy_g_m46Mo4xRkbg () mail ! gmail ! com
[Download RAW message or body]

On Tue, Aug 9, 2011 at 16:41, Mike Pall <mikelu-1108@mike.de> wrote:
> Lars Doelle wrote:
>>   The semantics of the composite assignment is inconsistent.
>
> Not a bug. Assignment order is explicitly undefined in Lua:
>
> http://lua-users.org/lists/lua-l/2006-06/msg00378.html
>
> --Mike
>
>

As I've understood it, when you write something like: a,b = 1,2 you
can view it as two simultaneous assignments. So to write a,a = 1,2
doesn't make a lot of sense - two different values are assigned to a
*at the same time*, so there's no telling which value it ends up with.
(You might even say the correct value is 3, i.e. 1 OR 2, if the
assignments were to literally be simultaneous...)

If you look at section 2.4.3 of the manual though it does state that
x, y = y, x is a valid way to swap variables. Given this and that Lua
seems to be a stack-based language, I suppose this can be read as:
push y; push x; pop y; pop x
i.e. everything after the = is pushed from left to right, then
everything before it is popped right to left.

-- 
Sent from my toaster.


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic