关闭

练习2.73-练习2.74

1.练习2.73 a 没有必要 b (define (insert-sum-proc) (define (deriv-sum exp var) (make-sum (deriv (car exp) var) (deriv (cadr exp) var))) (put 'deriv '+ deriv-sum) 'done) (define (...
阅读(434) 评论(0)

练习2.53-练习2.56

1.练习2.53 '(a b c) '((george)) '((y1 y2)) '(y1 y2) #f #f '(red shoes blue socks) 2.练习2.54 (define (equal? s1 s2) (cond ((and (null? s1) (null? s2)) true) ((or (null? s1) (null? s...
阅读(410) 评论(0)

练习2.48-练习2.51

1.练习2.48 (define (make-segment start end) (cons start end)) (define (start-segment seg) (car seg)) (define (end-segment seg) (cdr seg)) 2.练习2.49 (require (planet "sicp.ss" ("soegaard" "sicp...
阅读(355) 评论(0)

练习1.23-练习1.30

1.练习1.23 改后的代码如下: (define (find-divisor-better n a) (cond ((> (square a) n) n) ((divides?-better n a) a) (else (find-divisor-better n (next-2 a))))) (define (next-2 n) (if (= 2 n) (+ 1...
阅读(416) 评论(0)

练习2.21-练习2.35

1.练习2.21 (define (square-list items) (if (null? items) '() (cons (square (car items)) (square-list (cdr items))))) (define (square-list items) (map (lambda (x) (square x)) items)) 2...
阅读(377) 评论(0)

练习2.41-练习2.47

1.练习2.41 (define (seprate-except x except) (filter (lambda (couple) (let ((first (car couple)) (second (cadr couple))) (and (not (= first except))...
阅读(387) 评论(0)

练习2.11-练习2.20

1.练习2.11 (define (mul-interval x y) (let ((x1 (lower-bound x)) (x2 (upper-bound x)) (y1 (lower-bound y)) (y2 (upper-bound y))) (let ((zzx (and (>= x1 0) (>= x2 0))) (zzy (and (>= y1 0) (>...
阅读(385) 评论(0)

练习2.2-练习2.10

1.练习2.2 (define (make-segment start end) (cons start end)) (define (start-segment seg) (car seg)) (define (end-segment seg) (cdr seg)) (define (make-point x y) (cons x y)) (define (x-poin...
阅读(380) 评论(0)

练习2.1

1.练习2.1 (define (check-pos-neg a b) (or (and (not ( b 0)) (and (not (> a 0)) (< b 0)))) (define (make-rat n d) (let ((g (gcd (abs n) (abs d))) (posi (check-pos-neg n d))) (cons (/ (if...
阅读(344) 评论(0)

练习1.40-练习1.46

1.练习1.40 (define (cubic a b c) (define (cube x) (* x x x)) (lambda (x) (+ (cube x) (* a (square x)) (* b x) c))) (define (newtons-method g guess) (fixed-point (ne...
阅读(396) 评论(0)

练习1.35-练习1-38

1.练习1.35 (fixed-point (lambda (x) (+ 1 (/ 1 x))) 1.0) 2.练习1.36 不用平均阻尼方式: (fixed-point-display (lambda (x) (/ (log 1000) (log x))) 2.0) 结果为: 2. 9.965784284662087 3.004472209841214 6.2791957575071...
阅读(333) 评论(0)

练习1.31-练习1.34

最近对于Lisp的强大和高深还是深有体会的,可以将函数作为参数进行调用,这样在很大的程度上可以提高函数的抽象性,即将具有公共模式的函数进行抽象。例如在SICP中,首先将累加和的过程进行了抽象,然后在累加和的基础上抽象出了累乘积,进而又发现了累加和与累乘积的共同点,进一步抽象成了一个叫做accumulate的函数,这个函数的是这样的 (accumulate combiner null-value ...
阅读(357) 评论(0)

练习1.23-练习1.30

1.练习1.23改后的代码如下: (define (find-divisor-better n a) (cond ((> (square a) n) n) ((divides?-better n a) a) (else (find-divisor-better n (next-2 a))))) (define (next-2 n) (if (= 2 n) (+...
阅读(350) 评论(0)

练习1.18-练习1.22

1.练习1.18 (define (*-iter a b n) (cond ((= n 0) a) ((even? n) (*-iter a (double b) (halve n))) (else (*-iter (+ a b) b (- n 1))))) (define (* b n) (*-iter 0 b n)) Lisp真是强大啊,连 *-iter这种函数名也可以使用!...
阅读(415) 评论(0)

练习1.10-练习1.17

1.练习1.10 表达式的求值就不说了。 (define (f n) (A 0 n)) -------2n (define (g n) (A 1 n))-------2的n次方 (define (h n) (A 2 n))-------n个2的次方,例如:(h 4)表示为2的2次方的2次方的2次方 2.练习1.11 递归计算过程: (define (f1 n) (if (< n...
阅读(375) 评论(0)

练习1.1-练习1.9

1. 练习1.1 这个题没有什么好说的了,只要把代码敲出来,运行一遍就可以了。 2. 练习1.2 这个题应该不算难吧,没有看过别人的答案,我把我的贴出来吧。 (/ (+ 5 4 (- 2 (- 3 (+ 6 (/ 4 5))))) (* 3 (- 6 2) (- 2 7))) 3.练习1.3 我的方法是求出3个数的和,再将减去最小的数,算不上最好的方法吧,马马虎虎。 (def...
阅读(341) 评论(0)
    个人资料
    • 访问:99478次
    • 积分:2706
    • 等级:
    • 排名:第13836名
    • 原创:178篇
    • 转载:21篇
    • 译文:0篇
    • 评论:9条
    文章分类
    最新评论