[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
**Subject**: **Re: Testing for a sequence (was Re: Lua 5.2 Length Operator and tables (bug?)**
**From**: Eduardo Ochs <eduardoochs@...>
**Date**: Thu, 19 Apr 2012 17:27:09 -0300

On Thu, Apr 19, 2012 at 3:17 PM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
> The definition says "the set of its positive numeric keys is equal to
> {1..n} for some integer n." So that test returns false too easily.
> E.g.
>
>> a=table.pack(1,2,3,4)
>> =IsSequence(a)
> false
>
> Actually, if the purpose is to define when #t and the table library
> work, the definition should say: "the set of its positive integer
> numeric keys is empty or equal to {1..n} for some positive integer n."
>
0 is an integer, and when n is 0 we have {1,...,n} = {}.
By the way,
a = {10, 20, 30, 40, foo="bar",
[0]="z", [-2.5]=99, [-250]="!"}
is a sequence - according to the manual =) - but if we do a[6]=60
the result isn't a sequence anymore.
Cheers,
Eduardo Ochs