lua-users home
lua-l archive

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


On Fri, Jun 28, 2013 at 11:51 PM, Tim Hill <drtimhill@gmail.com> wrote:
> I still feel the Lua arrays are one of the more "odd" behaviors of the
> language. One moment its an array, the next its not. So when someone
> learning Lua says (a good question, btw), "ok, I get i'm not supposed to put
> nil in an array because they cannot be sparse, but what DO i put in?" .. and
> you say "it depends"


a different approach is not to use sequences, nor expect any table to
be one.  if you need an array-like structure that can hold nils as any
value, then just create a specific structure: a few short functions
that store values in a table while keeping score of the 'length'.  i
think penlight has one of these.

sometimes people here advocate here the idea of not using 'naked'
tables, but rather use them to build the exact structures you need.  a
vector structure is an easy one and can be just as efficient as native
arrays on other languages.

again, this could be just a new "it depends" answer... but that's how
engineering works, no? by knowing many useful idioms and using them to
avoid reinventing whenever possible.


--
Javier