lua-users home
lua-l archive

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

On Tue, Sep 13, 2016 at 11:32 PM,  <> wrote:
> I am new to lua and I want to understand the language. According book (Programming in Lua, 3rd edition):
> "More precisely, a sequence is a table where the numeric keys comprise a set 1, . . . , n for some n." (page 24)
> So table {10, nil, 30, 40} contains sequence {10} (n=1), which length is 1. Is there any other definition?
> It is very confusing and operator # can be unusable for tables, because in many cases I need to check sequences and I cannot trust this operator. It should return or 1 (book definition) or if holes in sequence break the sequence, it should return 0. Otherwise I will be pushed for every sequence check to check all array fields manually in some kind of loop.
> Tomas Lavicka
> (please excuse my bad english - I am not english native - but I hope that you understand, what I mean)

The definition in PiL 3rd Edition is written in a way that the
interpretation is ambiguous. The official definition in the Lua 5.2
manual clarifies on that to say "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 (see

That is to say, for a table to be a sequence, not only does it have to
have 1..n be non-nil, but it can't have any other positive numeric

/s/ Adam