Logical Operator: and

Predicates can be combined using the logical operators and, or, and not.

(and x_1 ... x_n ) evaluates each of x_1 ... x_n in order. As soon as any x_i returns #f, and returns #f without evaluating any remaining x's. If every x_i returns a value other than #f, the value of and is the value of x_n .


  (and (fast? x)
       (cheap? x)
       (out-of-control? x))

We can use and for safety checks. For example, the predicate (zero? x ) requires that x be a number. To prevent errors, we can test the argument first:


  (define (safe-zero? x)
    (and (number? x)
         (zero? x)) )

Contents    Page-10    Prev    Next    Page+10    Index