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 <>
           Roberto Ierusalimschy <> 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 5.3.2  Copyright (C) 1994-2015, PUC-Rio
RiscLua 6.3
x = { 1,2,[3]=3}
print (#x)
print (#{1,2,[4]="a"})

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 ...