lua-users home
lua-l archive

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


2016-07-26 10:57 GMT+02:00 Thomas Jericke <tjericke@indel.ch>:
> Am 26.07.2016 10:47, schrieb Dirk Laurie:
>>
>> 2016-07-26 8:55 GMT+02:00 Thomas Jericke <tjericke@indel.ch>:
>>
>>> As interesting statements like (a = a or 5) are there is
>>> one thing you always have to remember while programming Lua, testing for
>>> existence and testing for truth is the same unless you use explicit
>>> comparison.
>>
>> Actually, no. 'false' exists but does not test true. In fact, the type
>> 'boolean'
>> was introduced in Lua starting at Lua 2.1 precisely because a value with
>> that property was needed.
>>
> I think you didn't understand me, probably because I wasn't clear enough.
>
> If you use an if statement or use any boolean expression other than == you
> don't know whether you are testing for the value true of a boolean or for
> the existence of any value as you don't (always) know in beforehand if the
> type of that expression is boolean or not at programming time.
>
> Usually it doesn't matter as you know what kind of value you are dealing
> with, it is only a problem if you write some code that handles booleans and
> other types.

OK, actually we seem to agree.

I have on occasion exploited the trichotomy nil/false/everything else,
but commented it very carefully indeed. E.g.

--    'dvi' is the command for processing a DVI file, but there are two
--       reasons for not needing it and it is important for the automatic
--       selection of a TeX engine to know which is in effect. This is
--       possible by exploiting the the fact that Lua has two false values.
--         dvi == nil    "do not produce a DVI file" (but maybe PDF)
--         dvi == false  "do not process the DVI file" (but stop after TeX)