lua-users home
lua-l archive

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


> On Jun 30, 2016, at 7:11 AM, Philipp Janda <siffiejoe@gmx.net> wrote:
> 
> Am 30.06.2016 um 15:41 schröbte Gavin Wraith:
>> In message <20160630132301.GB21516@inf.puc-rio.br>
>>           Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
>> 
>>>> ˜ How should constructors set length? What are the lengths of {}, {1, 2} and {1, 2, [3]=3} ?
>>> 
>>> 0, 2, and 2.
>> A typo, I presume. Just testing with
>> *lua
>> Lua 5.3.2  Copyright (C) 1994-2015 Lua.org, PUC-Rio
>> RiscLua 6.3
>>> x = { 1,2,[3]=3}
>>> print (#x)
>> 3
>>> print (#{1,2,[4]="a"})
>> 2
> 
> We are not talking about the length of *any* table, but about the initial length that can be derived from a table literal. And the largest integer key used in array literal syntax is a valid option. The largest positive integer key in the whole table literal would also be possible, but I don't think `{ [1] = true }` should be an array ...
> 
> Philipp
> 
> 
> 

My feeling is it’s the largest *implicit* integer key (well, largest implicit key since all implicit keys are integers). This seems the least surprising to my mind.

—Tim