[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: New array type? (was: 'table' as fallback for tables)
- From: Jonathan Goble <jcgoble3@...>
- Date: Thu, 30 Jun 2016 21:01:56 -0400
The fact that this thread has ballooned into nearly 80 emails and is
still being debated suggests to me that perhaps we need to stop trying
to make tables do a job that they weren't designed to do, and instead
create a new array type separate from tables that is designed to do
that job.
Most languages have two distinct types for sequences and associative
arrays. Lua has just one type, the table, which is really good at the
latter, but doesn't do a very good job at the former. The ongoing
discussion proves that there is a need for a real sequence type
capable of holding `nil`, but I just don't think there is a good,
clean way for Lua, as it stands right now, to do that short of
creating a new type for sequences and deprecating tables for that
purpose (they would remain useful for associative arrays, of course).
A new type would have many advantages, chief among them elimination of
the need to store the length as a field in the table or metatable
(since the length would now be known and tracked by the C internals),
and elimination of the question of how to set the initial length from
a constructor (since array constructors probably wouldn't allow
explicit keys/indices).
I really think that this is the best way forward.