Exercise 4.26

Source code for Exercise 4.26.

(define (eval-unless exp env) 
  (eval# (make-if (unless-conditional exp)
                  (unless-exceptional exp)
                  (unless-usual exp))

(define (unless-conditional exp) (cadr exp))
(define (unless-usual exp) (caddr exp))
(define (unless-exceptional exp)
  (if (not (null? (cdddr exp)))
      (cadddr exp)

I can’t think of a reason why you would want to have unless as a procedure rather than a special form but the same goes for if. Perhaps there is some kind of logical analysis where it’s necessary to use map, foldr or filter with unless as the procedure or we may need to write a procedure at a higher level of abstraction that can take if, unless, or when as arguments to evaluate its results.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s