SICP 2.4 exercises


a) The dispatch is based on the operator symbol, and when the expression is a single number or a variable, there is no operator to identify. In general, the general procedure tests is the expression is a number or variable and deals with it accordingly. If there is an operator, then the operator symbol is used to retrieve the procedure needed to deal with the expression.


(define (install-deriv-package)
  (define (make-sum a1 a2)
  (cond ((=number? a1 0) a2)
        ((=number? a2 0) a1)
        ((and (number? a1) (number? a2)) (+ a1 a2))
        (else (list a1 '+ a2))))
  (define (addend s) (car s))
  (define (augend s) (cadr s))
  (define (sum exp var)
    (make-sum (deriv (addend exp) var)
              (deriv (augend exp) var)))

  (define (multiplier p) (car p))
  (define (multiplicand p) (cadr p))
  (define (product exp var)
     (make-product (multiplier exp)
                   (deriv (multiplicand exp) var))
     (make-product (deriv (multiplier exp) var)
                   (multiplicand exp))))
  (put 'deriv '+ sum)
  (put 'deriv '* product))

Really busy these days, so this is a record low rate of progress… 1/2 of a problem! Although b) is a decently large problem in itself. Weekend starts though so hopefully I can blast through the problems in the next couple days.


Leave a Reply

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

You are commenting using your 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