lua-users home
lua-l archive

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

"Greg Falcon" <> wrote:

> 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.
<rest snipped>

I fully agree with the observation that nil is less than first-class.
But I think your suggestion tries to shoehorn too many things into poor
old nil.

Indeed, I am convinced it is this sort of "overloading" that's the heart
of the problem: in some cases nil is used as a sort of data value and in
other cases as the absence of a value. Obviously, such a construction
can't work in all cases.

A sensible (IMHO) remedy has already been suggested a few times: there
should something *officially sanctioned* that means "I have a value
without actually having a value". Call it table.hole, call it sonofnil,
call it null (the latter had to be reserved words), call it what you
will: I think once such a "value" is a standard feature of Lua and used
correctly as such, many problems connected with nil will simply go away.

cheers  thomasl

web :