I'd like to do this in 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 instead to do something only if eq?
is false. How can I do that in my example?
Thanks
Boolean operations: and, or, not Since Scheme doesn't have a numeric "not equals" operator (like the != operator in C/Java/Python), we have to combine not and = in order to evaluate "not equals".
equal? and = are checking for value equivalence, but = is only applicable to numbers. If you're using Racket, check here for more information. Otherwise, check the documentation of your scheme implementation.
/= (not Equal to) (AutoLISP) If only one argument is supplied, /= returns T. Note that the behavior of /= does not quite conform to other LISP dialects. The standard behavior is to return T if no two arguments in the list have the same value.
If a number is evenly divisible by 2 with no remainder, then it is even. You can calculate the remainder with the modulo operator % like this num % 2 == 0 . If a number divided by 2 leaves a remainder of 1, then the number is odd. You can check for this using num % 2 == 1 .
You can use not
for that.
(cond
((not (eq? (car l) (cadr (order l))))
(cons (count (car (order l)) (order l))
(count-inorder-occurrences (cdr (order l))))
...)
You can use not
to negate the value of a predicate.
e.g. in an if
statement: (if (not (eq? A B)) <EVAL-IF-NOT-EQ> <EVAL-IF-EQ>)
or in a cond
you can do:
(cond ((not (eq? A B))
<EVAL-IF-NOT-EQ>)
.
.
.
(else <DEFAULT-VALUE>))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With