lua-users home
lua-l archive

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


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