Practice 4.26
把unless定义为if的派生表达式
(define (unless? exp) (tagged-list? exp 'unless))
(define (unless-condition exp)
(cadr exp))
(define (unless-usual-clause exp)
(caddr exp))
(define (unless-exceptional-clause)
(cadddr exp))
(define (unless->if exp)
(let ((predicate (unless-condition exp))
(consequent (unless-usual-clause exp))
(alternative (unless-exceptional-clause exp)))
(make-if predicate consequent alternative)))
在解释器中加入对unless的处理
((unless? exp) (eval (unless->if exp)))
如果是派生表达式,看以下高阶过程中
(define (foo bar a b c)
(bar a b c))
求值以下过程
(foo unless a b c)
在求值参数unless的时候在环境中找不到unless就会出错
如果unless是过程,在这个过程的求值中就不会出现问题