lua-users home
lua-l archive

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

Am 21.08.2016 um 14:39 schröbte Lorenzo Donati:

I think that many misunderstandings regarding tables and their usage
is that the reference manual is not very friendly for a newbie expecting
more traditional data structures. It took me several months to
understand clearly what a table *really is* (in Lua "philosophical"
sense, I mean): it is a (relatively) *low-level* data structuring

The point is that a table is a Lua table, not something else. If you
need a more traditional data structure you can implement it on top of
that. When I need more abstraction in complex applications, I simply see
tables as a low-level implementation mechanism. Otherwise, for simpler
scripts or programs, tables are good as they are.

Remember that one of the goal of Lua team is to provide mechanisms, not

The sequence concept *is* a policy on how to emulate arrays in Lua. Lua doesn't have real arrays, it has a circular buffer of 2^64 elements (as far as ordered, integer-indexed storage is concerned). If you want something smaller and non-circular, you have to keep track of the end yourself or somehow guess it from the contents of the table. Lua's sequence rules just make the guessing more efficient. Unfortunately, a sequence in the Lua sense is a leaky abstraction for an array like in other languages, hence the recurring newbie problems with it.

Soni only tries to remove this particular policy from the language, which is an admirable (although impractical in this case) goal, IMHO.

Dropping a useful feature (#) just because you cannot frame it in a
theoretically satisfying ideal is not useful for the general Lua
community IMO.

BTW, if you feel the need of removing #, try writing scripts simply
ignoring the existence of # and see if they turn out any better. If you
are expert enough you could hack into Lua source and remove that
functionality *and test whether your scripts end up cleaner*.

Yes, I think that's the way to go. Unfortunately, any alternative approach of emulating arrays will have a tough time to become widespread, because the sequence concept is built into the Lua language, the C API, and the standard library, so most people will just use it due to compatibility and convenience reasons.


-- Lorenzo