lua-users home
lua-l archive

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


>I look at lexically scoped and eventtable and I think "WOW, that's
>great. That will fix a whole bunch of nasty things in my code."  I look
>at false and I thing "What for?".  I guess false just isn't that useful
>for me.  I just hope you don't go and add 0, "0" and "" to the list of
>false values.

The problem that false is there to solve is that nil is currently trying
to be two very different things - "false" and "doesn't exist".

Let's say you have a very lengthy computation that returns either "true"
or "false".  Since it takes such a long time to compute, you decide to
cache the results in a table.  Look up the parameter in the table - if
you get nil, then either you've already done the calculation and the
answer was "false", or you haven't done the calculation yet.

Or maybe you're implementing an object system with inheritance.  If a
field isn't in the child's member table, then look it up in the parent.
How do you store "false"?

Or there's Markus Huber's example: you want default values for function
parameters.  If the function gets nil for that parameter, then it can't
tell if the parameter was missing, or if the caller is trying to pass
"false".

Introducing a real false value means that nil can be "doesn't exist",
and nothing else.  It eliminates a lot of ambiguity.
-Virus scanned and cleared ok