Chapter 2, Building Abstractions with Data

Section - 2.3 Symbolic Data

Exercise 2.57


We can just change procedures augend and multiplicand. Its interesting to see that how abstraction takes care of the rest.

1
2
3
4
5
6
7
8
9
10
11
12
13
(define (augend s)
  (if (null? (cdddr s))
      (caddr s)
      (cons '+ (cddr s))
  )
)  

(define (multiplicand p)
  (if (null? (cdddr p))
      (caddr p)
      (cons '* (cddr p))
  )
)

Test/Output:

1
2
3
> (display (deriv '(* x y (+ x 3)) 'x))
(+ (* x y) (* y (+ x 3)))
>