lua-users home
lua-l archive

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


Axel Kittenberger <axkibe@gmail.com> writes:

>> In C/C++ I would write !!condition. In  Lua "not not condition" ?
>
> I'm not sure how the ! operation is exactly defined in C(++)
> standards, is the result guaranteed to be 1(true) and 0(false) or just
> the usual 0 in case of false, or anything else in case of true. If it
> is the second, you gain nothing by !!.

That would be the first case of _any_ operator that is free to _invent_
values.  It would turn non-zero values into zero, and it would turn zero
into an ad-hoc non-zero invention of its own.

Even considering that you don't remember the behavior of the operator,
the semantics you imagine don't make any sense at all.

In contrast, the short-circuit operators && and || could conceivably
work like their Lua equivalents, returning their second argument
unchanged when not short-circuiting (and || could even return the first
argument unchanged _when_ shortcircuiting).  They don't (unfortunately
in most cases), but at least it would not be nonsensical if the language
designers had decided on a different behavior.

-- 
David Kastrup