[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Nil and false in Lua design
- From: Alexander Gladysh <agladysh@...>
- Date: Fri, 11 Oct 2013 22:47:10 +0400
On Fri, Oct 11, 2013 at 10:38 PM, Alexander Gladysh <agladysh@gmail.com> wrote:
> Hi, list!
>
> As we all know and learned to love, in Lua nil and false are false,
> and everything else is not.
>
> I vaguely remember reading years ago that this is so for historical
> reasons (Lua prior to 5.0 didn't have false), and if the language was
> designed from scratch as it is now, it would be different in this
> matter. (I think that this was said by someone from the Lua Team.)
>
> But I can't google up where did I read it...
>
> Does anyone else remember such reference?
As someone suggested off-list (thanks!), it is described in the
Evolution of Lua:
http://www.lua.org/doc/hopl.pdf
<quote>For a long time we resisted introducing boolean values in Lua:
nil was false and anything else was true. This state of affairs was
simple and seemed sufficient for our purposes. However, nil was also
used for absent fields in tables and for undefined variables. In some
applications, it is important to allow table fields to be marked as
false but still be seen as present; an explicit false value can be
used for this. In Lua 5.0 we finally introduced boolean values true
and false. Nil is still treated as false. In retrospect, it would
probably have been better if nil raised an error in boolean
expressions, as it does in other expressions. This would be more
consistent with its role as proxy for undefined values. However, such
a change would probably break many existing programs. LISP has similar
problems, with the empty list representing both nil and false. Scheme
explicitly represents false and treats the empty list as true, but
some implementations of Scheme still treat the empty list as
false.</quote>
Alexander.