What is the exclusive or functions in scheme? I've tried xor
and ^
, but both give me an unbound local variable error.
Googling found nothing.
What is the exclusive or functions in scheme? I've tried xor
and ^
, but both give me an unbound local variable error.
Googling found nothing.
If you mean bitwise xor of two integers, then each Scheme has it's own name (if any) since it's not in any standard. For example, PLT has these bitwise functions, including bitwise-xor
.
(Uh, if you talk about booleans, then yes, not
& or
are it...)
I suggest you use (not (equal? foo bar))
if not equals works. Please note that there may be faster comparators for your situiation such as eq?
As far as I can tell from the R6RS (the latest definition of scheme), there is no pre-defined exclusive-or operation. However, xor
is equivalent to not equals
for boolean values so it's really quite easy to define on your own if there isn't a builtin function for it.
Assuming the arguments are restricted to the scheme booleans values #f
and #t
,
(define (xor a b)
(not (boolean=? a b)))
will do the job.
Kind of a different style of answer:
(define xor
(lambda (a b)
(cond
(a (not b))
(else b))))