sicp-solutions/chapter-2/ex-2.73.txt
2025-10-01 15:46:25 +02:00

50 lines
1.8 KiB
Text

a) The predicates `number?` and `variable?` can't be assimilated because they
are checking the data type of the datum itself, not the value of a specific
symbol which can be found in a table.
b) Here I'll only write the most basic version of the procedures, since the
more elaborate versions were done in previous exercises.
(define (install-deriv-package)
(define (deriv-sum operands var)
(let ((addend (car operands))
(augend (cadr operands)))
(make-sum (deriv addend var)
(deriv augend var))))
(define (deriv-product operands var)
(let ((multiplicand (car operands))
(multiplier (cadr operands)))
(make-sum
(make-product multiplier
(deriv multiplicand var))
(make-product (deriv multiplier var)
multiplicand))))
(put 'deriv '+ deriv-sum)
(put 'deriv '* deriv-product)
'done)
c) exponential rule:
...
(define (deriv-expon operands var)
(let ((base (car operands))
(exponent (cadr operands)))
(if (constant? exponent var)
(make-product (make-product exponent
(make-exponentiation base
(make-sum
exponent
-1)))
(deriv base var))
(error "non-constant exponents not yet supported: DERIV" exponent))))
...
(put 'deriv '** deriv-expon)
...
d) if the dispatch line looked like this:
((get (operator exp) 'deriv) (operands exp) var)
the only part we would really have to change is the put lines for each of the
functions, like so:
(put 'deriv '+ deriv-sum) -> (put '+ 'deriv deriv-sum)