lua-users home
lua-l archive

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

On Sat, Aug 20, 2016 at 10:09 AM, Tim Hill <> 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 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.