SICP读书笔记2.4
练习2.73
- 因为这两种类型直接表示为scheme的数字和符号,没必要再次抽象成另一种类型。
2.
(define (install-sum-package)
(put 'deriv '+
(lambda (exp var)
(make-sum (deriv (addend exp) var)
(deriv (augend exp) var)))))
(define (install-product-package)
(put 'deriv '*
(lambda (exp var)
(make-sum
(make-product (multiplier exp)
(deriv (multiplicand exp) var))
(make-product (deriv (multiplier exp) var)
(multiplicand exp))))))
(define (install-exponentiation-package)
(put 'deriv '**
(lambda (exp var)
(let ((n (exponent exp))
(u (base exp)))
(make-product
n
(make-product
(make-exponentiation
u
(- n 1))
(deriv u var)))))))
- 把put时候的参数顺序对调一下就可以,比如原本的(put ‘deriv ‘) 改为(put ‘ ‘deriv)