Schematic: Cond Not Equal

I would like to do this according to the scheme:

if ((car l) != (car (cdr (order l))) do something 

in particular, I wrote this:

 ((eq? (car l) (car (cdr (order l))) ) (cons (count (car (order l)) (order l)) (count_inorder_occurrences (cdr (order l))))) 

but it compares (car l) with (car (cdr (order l)) for equality. I want to do something instead only if eq? is false. How can I do this in my example?

thanks

+4
source share
3 answers

You can use not for this.

 (cond ((not (eq? (car l) (cadr (order l)))) (cons (count (car (order l)) (order l)) (count-inorder-occurrences (cdr (order l)))) ...) 
+7
source

You can use not to negate the value of the predicate.

eg. in the if : (if (not (eq? AB)) <EVAL-IF-NOT-EQ> <EVAL-IF-EQ>)

or in cond you can do:

 (cond ((not (eq? AB)) <EVAL-IF-NOT-EQ>) . . . (else <DEFAULT-VALUE>)) 
+1
source

You really don't need cond or if unless you have a list of other cases. when may be what you are looking for. This is basically just the true case of if .

 (when (not (eq? (car l) (cadr (order l)))) (cons (count (car (order l)) (order l)) (count-inorder-occurrences (cdr (order l))) ) ) 
+1
source

All Articles