lua-users home
lua-l archive

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

Andrew Starks <> wrote:
> ...then you can live with the definition of a sequence being:
> "Any table containing a non-nil value at index 1. The length of the
> sequence is the number of non-nil keys from `1..n`."
> Simple. Easy to test. If you need more, Lua has ways to provide it.

I’m afraid you haven’t really answered my question. You’re proposing (or
using, at least) a definition of ‘sequence’ different from the one in Lua’s
manual. The manual explicitly says this:

> We use the term sequence to denote a table where the set of all positive
> numeric keys is equal to {1..n} for some non-negative integer n, which is
> called the length of the sequence (see §3.4.7).

And §3.4.7 adds:

> Note that a table like
>	{10, 20, nil, 40}
> is not a sequence, because it has the key 4 but does not have the key 3.
> (So, there is no n such that the set {1..n} is equal to the set of
> positive numeric keys of that table.)

My question to you was: *why* change the manual’s definition? That
definition is also simple and easy to test. And, frankly, it’s a lot more
intuitive to me than yours. (As far as any of this is intuitive, at

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