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

• Subject: Re: Lua 5.2 sequence definition - clarification needed
• From: Sam Roberts <vieuxtech@...>
• Date: Wed, 29 Jun 2011 16:03:53 -0700

```On Wed, Jun 29, 2011 at 12:25 AM, Lorenzo Donati
<lorenzodonatibz@interfree.it> wrote:
> * 1st point
>
> Section 3.4.6 of Lua 5.2 refman says:
>
> "Unless a __len metamethod is given, the length of a table t is only defined
> if the table is a sequence, that is, the set of its positive numeric keys is
> equal to {1..n} for some integer n."

...

> "Note, however, that non-numeric keys *or non-positive numeric keys* do not interfere with whether a table is a sequence."

Wouldn't you also want to list keys of zero and positive integer keys > n+1?

Its just a note, it doesn't have to be an exhaustive description of
the complement of the set of positive integers from {1...n}.

...

> Therefore I would modify slightly the definition:
>
> "Unless a __len metamethod is given, the length of a table t is only defined
> if the table is a sequence, that is, the set of its positive numeric keys is
> equal to {1..n} for some *non-negative* integer n."
>
> This would rule out that (admittedly unintuitive, but correct)
> misinterpretation.

In the set of positive keys {1..n}, how could it be correct to think n
is not positive?

And saying n is non-negative isn't the same as saying n is positive. 0
is non-negative and non-positive.

Cheers,
Sam

```