lua-users home
lua-l archive

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

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.

If I am not mistaken, JavaScript has both "null" and "undefined" values; "undefined" has the same role as "nil" does in Lua, and "null" has the meaning you suggest. It seems to me that introducing a new "null" value as you suggest would be an elegant way of solving the problems of "nil" without introducing any new ones, with the only small drawback that "null" becomes a reserved word.

It would be possible to simulate by simply adding "null = {}" somewhere, but then this would evaluate to "true" in a boolean context, so I think it would be best if it were added to the base language.

Chris Swetenham