习题1.1-1.5
- 習題1.1
1 ]=> 10
;Value: 10
1 ]=> (+ 5 3 4)
;Value: 12
1 ]=> (- 9 1)
;Value: 8
1 ]=> (/ 6 2)
;Value: 3
1 ]=> (+ (* 2 4) (- 4 6))
;Value: 6
1 ]=> (define a 3)
;Value: a
1 ]=> (define b (+ a 1))
;Value: b
1 ]=> (+ a b (* a b))
;Value: 19
1 ]=> (= a b)
;Value: #f
1 ]=> (if (and (> b a) (< b (* a b)))
? ? ? ? ? b
? ?a)
;Value: 4
1 ]=> (cond ((= a 4) 6)
? ((= b 4) (+ 6 7 a))
? ? ? ? ? ? ? ?(else 25))
;Value: 16
1 ]=> (+ 2 (if (> b a) b a))
;Value: 6
1 ]=> (* (cond ((> a b) a)
? ? ? ? ? ((< a b) b)
?(else -1))
?(+ a 1))
;Value: 16
- 習題1.2
1 ]=> (/ (+ 5 4 (- 2 (- 3 (+ 6 (/ 4 5)))))
? (* 3 (- 6 2) (- 2 7)))
- 習題1.3
1 ]=> (define (<= x y) (or (< x y) (= x y)))
;Value: <=
1 ]=> (define (sumoftwobigger x y z)
? ? ? ? ? (cond ((and (<= x y) (<= x z)) (+ y z))
? ? ? ? ? ? ? ? ?((and (<= y z) (<= y x)) (+ x z))
? ? ??((and (<= z x) (<= z y)) (+ x y))))
;Value: sumoftwobigger
1 ]=> (sumoftwobigger 1 2 3)
;Value: 5
1 ]=> (sumoftwobigger 4 2 5)
;Value: 9
根據http://sicp.readthedocs.org/en/latest/chp1/3.html的說法,該題翻譯有誤,應該是求最大兩個數的平方和,上面答案略做更改即可。
- 習題1.4
如果b為正數,則條件表達式中取“+”號,使a+b,否則條件表達式取“-”,使a-b。
- 習題1.5
如果解釋器為應用序求值,(p)會在 test處展開,因此進入死循環。如果解釋器是正則序求值,則(p)會在最后求值,但是在if中選擇了求0值,故不會求(p)的值。這里http://sicp.readthedocs.org/en/latest/chp1/5.html解釋更加詳細。
轉載于:https://www.cnblogs.com/Godsake/archive/2013/01/06/2848203.html
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
- 上一篇: 2012总结--第1篇--技术篇
- 下一篇: Eclipse 各种快捷键