lua-users home
lua-l archive

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


Malma <malma@kaluga.net> wrote:
> I think this explanation must be in official doc if it's a source of
> confusion.

Are you saying that it *should* be in the official documentation or that it
*is* in the official documentation?

> print(# {[1] = 10, [2] = 20, [3] = nil, [4] = nil, [5] = 40} ) -- is not
> sequence ?

Correct. That is not a sequence. As it says in #3.4.7, {10, 20, nil, 40} is
not a sequence “because it has the key 4 but does not have the key 3. In
your table above, there is a key 5, but no key 3 or 4. Hence, not
a sequence.

> print(# {10, 20, nil, nil, 40} ) -- is sequence ?  From doc: Note that
> a table like {10, 20, nil, 40} is not a sequence...

You’re asking, but you also cite the relevant bit of the documentation, so
I think that you know the answer already: {10, 20, nil, nil, 40} is not
a sequence. For the reason given above from the manual.

Here’s one that I consider a bit odd—and I’m testing my own understanding
now. The following *is* a sequence, according to the definitions in Lua’s
manual: {10, 20, nil}. That’s a sequence, and it’s length is 2. It’s
a sequence because there is an n such that “the set of [the table’s]
positive numeric keys is equal to {1..n} for some non-negative integer n.”
And that n (here 2) is it’s length. (Someone please correct me if I’m
wrong.) Presumably this means that {[1] = 10, [2] = 20, [3] = nil} is also
a sequence, although with a more verbose constructor.

The information *is* in the manual, although you are certainly not the
first person to wish that it were either clearer or less brief or both.

P
-- 
We have not been faced with the need to satisfy someone else's
requirements, and for this freedom we are grateful.
    Dennis Ritchie and Ken Thompson, The UNIX Time-Sharing System