Reputation: 781
I have a conditional, and I want to test to see if two things are true. How can I do an equivalent of &&
or ||
from Java in Scheme?
Upvotes: 1
Views: 19237
Reputation: 45657
It's important to note that and
and or
don't return #t
, but rather, the truthy value for which the condition was satisfied: either the last true value in and
or the first true value in or
.
(and 1 2) => 2
(and #f 2) => #f
(and #t 6) => 6
(or 1 2) => 1
(or #f #f 0 #f) => 0
Upvotes: 3
Reputation: 118651
Also note that not only does:
(and (equals? var1 var2) (equals? var3 var4))
work, but also:
(and (equals? var1 var2) (equals? var3 var4) (equals? var5 var6))
vs
(and (and (equals? var1 var2) (equals? var3 var4)) (equals? var5 var6))
(and ...) and (or ...) take any number of arguments.
Upvotes: 4