3 (define (tagged-list? exp tag)
8 (define (make-if predicate consequent alternative)
9 (list 'if predicate consequent alternative))
12 (define (and? expr) (tagged-list? expr 'and))
13 (define (eval-and expr env) (eval-and-predicates (cdr expr) env))
15 (define (eval-and-predicates expr env)
16 (cond ((null? expr) #t)
17 ((eval (car expr) env) (eval-and-predicates (cdr expr) env))
21 (define (or? expr) (tagged-list? expr 'or))
22 (define (eval-or expr env) (eval-or-predicates (cdr expr) env))
24 (define (eval-or-predicates expr env)
25 (cond ((null? expr) #f)
26 ((eval (car expr) env) #t)
27 (else (eval-or-predicates (cdr expr) env))))
29 ;; derived expressions
30 (define (and->if expr)
31 (expand-and-predicates (cdr expr)))
33 (define (expand-and-predicates expr)
34 (cond ((null? expr) '#t)
35 (else (make-if (car expr)
36 (expand-and-predicates (cdr expr))
40 (expand-or-predicates expr))
42 (define (expand-or-predicates expr)
43 (cond ((null? expr) '#f)
44 (else (make-if (car expr)
46 (expand-or-predicates (cdr expr))))))