[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: C API - lua_next traversal of "array" table
- From: "Soni L." <fakedme@...>
- Date: Mon, 22 Aug 2016 06:28:21 -0300
On 22/08/16 05:43 AM, Viacheslav Usov wrote:
On Sat, Aug 20, 2016 at 10:09 AM, Tim Hill <drtimhill@gmail.com
<mailto:drtimhill@gmail.com>> wrote:
> Incorrect. The definition defines if a table is ALSO a sequence. It
does say it must ONLY be a sequence.
I did misinterpret what the definition said, but you also did it here.
What that really means is that we simply do not have a well-defined
concept of "array" in Lua. So let's define it.
A table has an /array part/ if it has a subset of keys that is {1 ..
n} for some positive integer n, with corresponding non-nil values;
those keys and their values are the array part.
A table doesn't have an array part because my implementation uses linked
lists.
A sequence is a table that has an array part. A sequence that is equal
to its array part is an /array/. A sequence whose keys that are not in
its array part are not numbers is /regular/.
The length operator # has an intuitive and unsurprising meaning only
when applied to arrays. The length operator can still be used
coherently with regular sequences. Its use against other kinds of
tables should, in my opinion, be avoided.
Cheers,
V.
--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.