lua-users home
lua-l archive

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


>
> local function IsSequence( aTable )
> Âfor aKey in pairs( aTable ) do
> Â Âif not( type( aKey ) == 'number' and aKey > 0 and aKey == math.floor( aKey ) and aTable[ math.max( aKey - 1, 1 ) ] ~= nil ) then
> Â Â Âreturn false
> Â Âend
> Âend
>
> Âreturn true
> end
>

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."