lua-users home
lua-l archive

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


It was thus said that the Great Roberto Ierusalimschy once stated:
> > Well, I cannot speak for a 'community of best practice' but this is how I
> > see the problem. Lua does not have null, as understood in other languages.
> 
> I think it does: it is called 'nil'. What Lua does not have is a way to
> store 'nil' in a table.

  There are two concepts here, reflected in the following code:

	x = function() end
	y = function() return nil end

  In Lua today, both x and y will nil (or in other words, they don't exist). 
But what's really going on here?  In the first case, the function returns
nothing, so there is nothing to put into x.  In the second case, the
function returns nil, so there *is* something to put into y, but it's a
value that typically means "invalid" or "not applicable" or even "nothing to
see here".  

  It's that last point that's problematic I think.  There is a difference
(in my opinion) between a function that returns nothing, and a function that
returns nil.  In Lua, "nil" plays both roles, and in a lot of cases, that's
okay.  But there are times when having a distinction between "nothing" and
"invalid" is critical and it's something that Lua lacks.  So right now, you
have:

	Platonic essence	Lua

	nothing			nil
	nil			nil

  What people seem to be asking for is:

	Platonic essence	Lua	NeoLua
	nothing			nil	empty [1]
	nil			nil	nil

	[1] Personally, I like the term "nothing" instead of "empty" as I
	feel it better reflects what is happening, but hey, it's a start.

  (or maybe I have it backwards, that the Platonic essence of "nothing"
should be nil, while the Platonic essence of "nil" should be empty)

  Anyway, that's how I see it.

  -spc (And I've been able to work around the nilless tables of Lua)