lua-users home
lua-l archive

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

> The recent thread about lists and nil got me thinking about the ways
> in which nil isn't a first-class data type in Lua.  Of course, the
> focus of that thread was on sparse arrays and vararg lists.  I've been
> thinking about another limitation of nil -- that the generic for loop
> doesn't allow an iterator to provide nil as a value.


Another approach -- already mentioned several times here -- is to use tuples.
You could then pass and return tuples to/from vararg functions. It would be
easy to iterate over them (similarly to ipairs but checking for the number of
arguments instead of a nil value), and the iteration would respect nils.
Moreover, tuples can be implemented as closures and no change to the language
would be necessary (a new datatype is a big change, btw).


A mathematician is a device for turning coffee into theorems.
        -- P. Erdos 

Luis Carvalho
Applied Math PhD Student - Brown University
PGP Key: E820854A <>