[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: Petite Abeille <petite.abeille@...>
- Date: Thu, 19 Apr 2012 20:33:18 +0200
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…