views:

64

answers:

3

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?

A: 
(and (equals? var1 var2) (equals? var3 var4))
Corey
+2  A: 

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.

Will Hartung
+1  A: 

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
erjiang