lua-users home
lua-l archive

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

2013/6/9 Tim Hill <>:
> As the Lua docs state, an array is a table with a sequence
> of elements from 1..N.
> But my question is: is it ok to build the array out of order?
> For example:
> a = { 1, [3]=3 }
> a[2]=2
> Is "a" an array?

The actual term is "sequence" but I know what you mean. Yes, it is.

> Lua *seems* to think it is (#a returns 3), but the Lua docs seems
> to be a bit vague on this (it seems to be implied by the term
> "sequence" in the ref manual).

Not vague, but not labouring the point either. Let's say the Manual
is mathematically precise on the subject.

    We use the term sequence to denote a table where the set of all
    positive numeric keys is equal to {1..n} for some integer n,
    which is called the length of the sequence.

Actually, the routines that depend on this property are not confused
by positive numeric keys that can't be taken for integers, but the
above is what it says.