lua-users home
lua-l archive

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


On 20 April 2012 13:18, Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
>> Here is a table which from what I can tell is a sequence according to
>> the manual yet once you look at the byte code and how the instructions
>> are generated you can see why it is not.
>> Lets take the example of not a sequence from the manual and adjust it[1]
>>
>> [...]
>> Lua 5.2.0  Copyright (C) 1994-2011 Lua.org, PUC-Rio
>> > do
>> >> a={10,20,nil,[3]=30,40}
>> >> print(#a)
>> >> end
>> 4
>>
>> Huh so what is wrong? It looks like a table as it has entries for
>> 1,2,3 and 4 also the implementation being used tells us it has four
>> entries because it is a sequence, or is it?
>>
>> [...]
>>
>> A little of topic and a corner case I know, but have I missed/misread
>> a part of the manual which specifies this behaviour?
>
> Nowhere the manual says the items are processed in a specific order.
> Your constructor specifies two different values for 3 (nil and 30), so
> Lua is free to set nil and then 30 or 30 and then nil.
>
> -- Roberto
>

The problem with that is that other implementations can give a
different result for the exact same table.

LuaJIT 2.0.0-beta8 -- Copyright (C) 2005-2011 Mike Pall. http://luajit.org/
JIT: ON CMOV SSE2 SSE3 SSE4.1 fold cse dce fwd dse narrow loop abc fuse
> do
>> local a = {10,20,nil,[3]=30,40}
>> for k,v in pairs(a) do print(k,v) end
>> end
1	10
2	20
3	30
4	40

Liam