lua-users home
lua-l archive

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


On Apr 19, 2012, at 8:17 PM, Dirk Laurie 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

Yes. table.pack adds a 'n' field somewhere along the way. And 'n' is not a number.  

That's why there is another method called HasSequence which in more lenient with mixed tables :D

In practice, this is not so much about toeing the line to any given definition in the manual, but more pragmatically to tell the difference between what can be stored in say, a JSON array [] vs. an object {} or a Java List vs. Map or Cocoa NSArray vs. NSDictionary, etc, etc…