lua-users home
lua-l archive

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


On 10/11/2013 06:58 PM, Luiz Henrique de Figueiredo wrote:
I can't imagine a system in which nil ISN'T falsy...
In the HOPL paper we say that, if things were different, using nil
in a logical expression should probably raise an error, just like in
arithmetic expressions.


If you ever happen to reconsider this, I am a big supporter for a change. For me it is a real joy to read code in a language that only accepts boolean values for logical expressions including if and while conditions. You see much better what it tested for if it is always written out.

I see only few cases where a nil slipping in as a false is really a problem. But if you test for nil with "if X then" a false can slip in as a nil.
We probably all know this case:

function x (a)
    a = a or true -- default 2
    print(a)
end

x(false)
-- prints "true"

--

Thomas