Fork me on GitHub

部分习题:

exercise 2.73

a)对求导过程来说,数字和变量的表示形式对任何“类型标志”(例如+)都是一致的,没有必要实现不同的表示方式。

b)

 1 (define (install-deriv-sum-package)
 2   ;internal procedure
 3   (define (addend s) (cadr s))
 4   (define (augend s) (caddr s))
 5   (define (make-sum a1 a2)
 6     (cond ((=number? a1 0) a2)
 7       ((=number? a2 0) a1)
 8       ((and (number? a1) (number a2)) (+ a1 a2))
 9       (else (list '+ a1 a2))))
10   ;interface
11   (put 'addend '+ addend)
12   (put 'augend '+ augend)
13   (put 'make-sum '+ make-sum)
14   (put 'deriv '+ (lambda (exp var)
15            (make-sum (deriv (addend exp) var)
16                  (deriv (augend exp) var))))
17   'done)
18 
19 (define (install-deriv-product-package)
20   ;internal pricedure
21   (define (multiplier p) (cadr p))
22   (define (multiplicand p) (caddr p))
23   (define (make-product p1 p2)
24     (cond ((or (=number? p1 0) (=number? p2 0)) 0)
25       ((=number? p1 1) p2)
26       ((=number? p2 1) p1)
27       ((and (number? p1) (number? p2)) (* m1 m2))
28       (else (list '* p1 p2))))
29   ;interface
30   (put 'multiplier '* multiplier)
31   (put 'multiplicand '* multiplicand)
32   (put 'make-product '* make-product)
33   (put 'deriv '* (lambda (exp var)
34            (make-sum (make-product (multiplier exp)
35                        (deriv (multiplicand exp) var))
36                  (make-product (deriv (multiplier exp) var)
37                        (multiplicand exp)))))
38   'done)

exercise 2.74

a)人事文件应当有一个tag信息,用于识别该文件属于哪一个分支机构。

exercise 2.75

1 (define (make-from-mag-ang x y)
2   (define (dispatch x y)
3     (cond ((eq? op 'real-part) (* x (cos y)))
4           ((eq? op 'imag-part) (* x (sin y)))
5           ((eq? op 'magnitude) x)
6           ((eq? op 'angle) y)
7           (else (error "Unkown op -- MAKE-FROM-MAG-ANG" op))))
8   dispatch)
posted on 2012-11-24 20:07  sungoshawk  阅读(236)  评论(0编辑  收藏  举报