Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you express Boolean negation in Scheme?

In C and C++, the ! negates the result:

if( !( a == b ) )

In Scheme, I found only eq?. How do I say "not equal"? Or we have to explicitly say

(eq? #f (eq? expr expr))
like image 701
Chan Avatar asked Apr 21 '11 23:04

Chan


People also ask

How do you negate a Boolean expression?

To negate a Boolean expression you simply have to apply the DeMorgan theorem recursively: (1) The negation of a sum is the product of the negated variables. (2) The negation of a product is the sum of the negated variables.

Is there an or operator in Scheme?

Scheme provides us with at least three useful logical operators: AND, OR, and NOT. The only value in Scheme that "means" false is #f. All other values are interpreted as true (including the empty list).


1 Answers

Scheme has a not, so you could do: (not (eq? expr1 expr2))

like image 141
Jerry Coffin Avatar answered Nov 04 '22 16:11

Jerry Coffin