lua-users home
lua-l archive

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



On Sep 16, 2016, at 2:38 PM, Soni L. <fakedme@gmail.com> wrote:

A boolean is a 1-bit number. An integer is a 32- or 64-bit number.

Bitwise not applies to both.

Bitwise not on a boolean is ((~TRUE)&1), which produces the same value as (!TRUE).

And Rust uses ! for both bool not and bitwise not, granted it does have a complex and potentially turing-complete type system.

A boolean is a logical type with a value of true or false. It may internally be represented as a single bit, but that is an implementation detail. Bitwise inversion (a more accurate name for bitwise NOT) does not apply to booleans, any more than it applies to hats.

C and its various offspring frequently allow an integer value to be INTERPRETED in a boolean manner (using the zero vs non-zero convention). For this reason, in this class of language, it is valid to use boolean operators on integers (though with caution), since the integer type is overloaded. This is not the case for Lua, so your assertion is incorrect.

—Tim