[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
**Subject**: **Re: Lua 5.2 Length Operator and tables (bug?)**
**From**: Dirk Laurie <dirk.laurie@...>
**Date**: Tue, 17 Apr 2012 20:57:58 +0200

>>
>> t = { 1, 2 }
>> t[ 2 ] = nil
>> t[ 3 ] = 3
>>
>> print( t[ 1 ], t[ 2 ], t[ 3 ], issequence( t ) )
>
> That's not a counterexample, that's just a special case. In this case,
> this test is reporting that t IS a sequence, and #t is returning the
> length of it -- what it isn't reporting is that there are also
> non-sequence parts of t. If you want THAT test, of course, you can
> code for it too.
>
>From the 5.2 manual:
We use the term sequence to denote a table where the set of all
positive numeric keys is equal to {1..n} for some integer n, which
is called the length of the sequence
In this case, the set of all positive numeric keys is {1,3} — you can
verify that by iterating through pairs() — which does not satisfy the
definition.