Prev Up Next

Scheme provides special forms for boolean conjunction (``and'') and disjunction (``or''). (We have already seen (sec 2.1.1) Scheme's boolean negation not, which is a procedure.)

The special form and returns a true value if all its subforms are true. The actual value returned is the value of the final subform. If any of the subforms are false, and returns #f.

(and 1 2)  => 2
(and #f 1) => #f

The special form or returns the value of its first true subform. If all the subforms are false, or returns #f.

(or 1 2)  => 1
(or #f 1) => 1

Both and and or evaluate their subforms left-to-right. As soon as the result can be determined, and and or will ignore the remaining subforms.

(and 1 #f expression-guaranteed-to-cause-error)
=> #f

(or 1 #f expression-guaranteed-to-cause-error)
=> 1

Prev Up Next

Log in or register to write something here or to contact authors.