lua-users home
lua-l archive

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


Thank you very much for all your answers.

Romeu.


On Mon, Apr 8, 2013 at 1:33 PM, Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
> In 5.2, the length "is only defined if the table is a sequence", but
> it's not clear whether applying the length operator to such a table is
> "undefined behavior" as that term is used in languages such as C.

Not at all. Only the resulting value is undefined, not the behavior of
the operation.


> For that matter, in 5.2 it doesn't seem to actually be defined that
> the length of a table with no positive numeric keys is 0 (does the set
> "{1..0}" have any more meaning than something like "{1..-1}"?)

Both have the same "quantity" of meaning :) I read {1..n} as a shorthand
for {i | 1 <= i and i <= n}, so both {1..0} and {1..-1} denote the empty
set. (OK, so the length of an empty set could be -1, but I do not think
this is what confuses people.)


> And it seems the length of tables with positive numeric keys that
> are not integers (e.g. { 'a', [1.5]='b', 'c' }) is not technically
> defined, either.

Yes.

-- Roberto