SICP 题解集合
1.1(略)
1.2
1 biwascheme>
2 (/ (+ 5 4 (- 2 (- 3 (+ 6 (/ 4 5)))))
3 (* 3 (- 6 2) (- 2 7)))
4 => -0.24666666666666667
1.3
1 biwascheme>
2 (define (BiggerSum x y z)
3 (define s1 (+ x y))
4 (define s2 (+ x z))
5 (define s3 (+ y z))
6 (cond ((and (> s1 s2) (> s1 s3)) s1)
7 ((and (> s2 s1) (> s2 s3)) s2)
8 (else s3)
9 )
10 )
11 biwascheme> (BiggerSum 2 1 3)
12 => 5
1.4 (略)
1.5
若解释器采用正则序求值,Ben可以看到解释器顺利返回0;
若解释器采用应用序,则程序会陷入无限循环。
1.6 (略)
1.7
1 (define (square x) 2 (* x x)) 3 4 (define (improve guess x) 5 (average guess (/ x guess))) 6 7 (define (average x y) 8 (/ (+ x y) 2)) 9 10 (define (good-enough? guess0 guess1) 11 (< (abs (- (/ guess0 guess1) 1)) 0.001)) 12 13 (define (sqrt-iter guess x) 14 (define new-guess (improve guess x)) 15 (if (good-enough? guess new-guess) 16 guess 17 (sqrt-iter new-guess x))) 18 (define (sqrt x) 19 (sqrt-iter 1.0 x))
1.8
1 (define (square x) 2 (* x x)) 3 (define (improve guess x) 4 (/ (+ (/ x (square guess)) (* 2 guess)) 5 3) 6 ) 7 (define (good-enough? guess0 guess1) 8 (< (abs (- (/ guess0 guess1) 1)) 0.001)) 9 (define (cube-root-iter guess x) 10 (define new-guess (improve guess x)) 11 (if (good-enough? guess new-guess) 12 guess 13 (cube-root-iter new-guess x))) 14 (define (cube-root x) 15 (cube-root-iter 1.0 x))
“这些年我一直提醒自己一件事情,千万不要自己感动自己。大部分人看似的努力,不过是愚蠢导致的。什么熬夜看书到天亮,连续几天只睡几小时,多久没放假了,如果这些东西也值得夸耀,那么富士康流水线上任何一个人都比你努力多了。人难免天生有自怜的情绪,唯有时刻保持清醒,才能看清真正的价值在哪里。”