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.

> a=table.pack(1,2,3,4)
> =IsSequence(a)

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