lua-users home
lua-l archive

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

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:


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.

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.

Ross Berteig                     
Cheshire Engineering Corp. 
+1 626 303 1602