lua-users home
lua-l archive

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

I think the behaviour is  dangerous.

> =#{nil,2}
> =#{[2]=2}

The behaviour changes depending on the syntax of construction.

David B

On 3/6/06, Dolan, Ryanne Thomas (UMR-Student) <> wrote:
> The length operator only guarantees a predictable result in the case of an "array" without holes, like: {1, 2, 3, 4, 5}.  If there are any holes at all, then you can't rely on the # operator to give you the result you expect.  This is why the manual is a bit confusing; it gives a definition that is always valid, but not really useful except in the special case of an array without holes.
> So, your experiment with {nil, 2, 3, 4, 5} gives you a valid result (according to the manual's definition) but it isn't a useful value.  This is not a bug at all, but an optimization.