[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: The 4 negations of Lua
- From: "Soni L." <fakedme@...>
- Date: Sun, 18 Sep 2016 09:57:55 -0300
On 17/09/16 01:43 AM, Tim Hill wrote:
On Sep 16, 2016, at 2:38 PM, Soni L. <fakedme@gmail.com
<mailto: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
Is there any good reason to not do it the Rust way? Lua has a separate
boolean type, just like Rust. You can't add/subtract/multiply/divide a
Rust boolean with a Rust integer and you can't
add/subtract/multiply/divide a Lua boolean with a Lua integer. But what
Rust does let you do is use bitwise not on a boolean, and it saves an
operator.
--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.