lua-users home
lua-l archive

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


On Jul 22, 2016 10:11 AM, "nobody" <nobody+lua-list@afra-berlin.de> wrote:
>
>  - a boolean or nil: __false is true -> value is false
>                      __false is false (or nil) -> value is true
> (The true/false order was chosen such that you're not jumping around in
> the truth table: (__false = nil) ~ (__false = false) whereas it would
> probably be (__bool = nil) !~ (__bool = false).)

While I understand the reasoning, the double negation here is confusing. I'd find __bool much easier to understand: if it's a boolean, that's the truth value; if it's a function, call it to determine the truth value; if it's nil, the standard logic applies (anything that isn't `false` or `nil` is true).

If we were designing a new language, I'd be tempted to say it should raise an error when comparing a value which is not a boolean to one that is (where having __bool counts as being a boolean).