SICP

Exercise 1.5

(define (p) (p)) (define (test x y) (if (= x 0) 0 y)) Then we evaluates the expression (test 0 (p)) What behavior will it with an interpreter that uses applicative-order evaluation? (test 0 (p)) ->(test 0 (p)) ->(test 0 (p)) ->.....When th…

Exercise 1.4

Use this observation to describe the behavior of the following procedure; (define (a-plus-abs-b a b) ((if (> b 0) + -) a b)) > (a-plus-abs-b 1 5) ->6 > (a-plus-abs-b 1 -5) ->6 Scheme can allows for combinations whose operators are compound…

Exercise 1.3

(define (square x) (* x x)) (define (sum-of-square x y) (+ (square x) (square y))) (define (top-two-sum-square a b c) (cond ((and (>= b a) (>= c a)) (sum-of-square b c)) ((and (>= a b) (>= c b)) (sum-of-square c a)) (else (sum-of-square a …

Exercise 1.2

Translate the following expression into prefix form 5+4+(2-(3-(6+4/5)))/3(6-2)(2-7) (/ (+ 5 4 (- 2 (- 3 (+ 6 (/ 4 5))))) (* 3 (- 6 2) (- 2 7))) ->-0.246

Exercise 1.1

I just write the results... 10 ->10 (+ 5 3 4) ->12 (- 9 1) ->8 (/ 6 2) ->3 (+ (* 2 4) (- 4 6)) ->6 (define a 3) (define b (+ a 1)) (+ a b (* a b)) ->19 (= a b) ->false (if (and (> b a) (< b (* a b))) b a) ->4 (cond ((= a 4) 6) ((= b 4) (+ …

1.1 The Elements of Programming

prefix notation : 前置記法 pretty-printing : 改行を入れるなどして、コードをフォーマットして書くこと[1.1.2 Naming and the Environment] はSchemeでの関数名の規約や評価法が書いてある。Schemeの一般的な関数定義 (define (<name> <fomal parameters>) <body>) 式の評価順について </body></fomal></name>…