• Subject: Re: The 4 negations of Lua
• From: "Soni L." <fakedme@...>
• Date: Fri, 16 Sep 2016 18:38:58 -0300

```

On 16/09/16 06:25 PM, Ross Berteig wrote:
```
```On 9/16/2016 12:58 PM, Soni L. wrote:
```
```On 17/09/16 02:18 AM, Martin wrote:
```
```On 16-09-05 12:29 PM, Soni L. wrote:
```
```Lua has 4 forms of negation:

-
~
not
~=

Yet only 2 of them can be overloaded.

It's cool that Lua has 4 forms of negation tho.
```
```As I understand "-" is for general numbers, "~" for integer numbers,
"not" for general logic and "~=" for equivalence logic. From them only
"~=" may be dropped and reformulated as "not ==".
```
```
What, "~true" isn't a good replacement for "not true"? A boolean has a
single bit so bitwise negation on booleans makes sense...
```
```
```
In C, bitwise and boolean not are separate operators. Any non-zero integral value is equivalent to TRUE, but the boolean operators are specified to produce the single value 1 for any true expression. So the expressions (!TRUE) and (~TRUE) are *very* different. In particular, (~TRUE) will produce a value that is also true, which may not be what you meant.
```
```
I see a strong but not always stated goal of Lua (and C too, before too many standards committees got their teeth in it) as to have an expressive language that is small enough, but not too small.
```
```
IMHO, there is no good argument for using the same operator for boolean and bitwise not in a language you intend people to actually use, understand, and debug.
```
```
```
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.
```
```
The bad argument is to claim the language is too complicated, and should have fewer operators. The reducto ad absurdum is that a Turing machine is Turing-complete, but you wouldn't want to actually use one for anything practical.
```
```
```
--
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.

```