問題1.46 – SICP(計算機プログラムの構造と解釈)その24
問題1.46 (iterative-improve [予測値が十分であるかを調べる手続き] [予測値を改良する手続き]) (define (iterative-improve enough? improve) (lambda (guess) (define (iter guess) (if (enough? guess) guess (iter (improve guess)))) (iter g…続きを読む
問題1.46 (iterative-improve [予測値が十分であるかを調べる手続き] [予測値を改良する手続き]) (define (iterative-improve enough? improve) (lambda (guess) (define (iter guess) (if (enough? guess) guess (iter (improve guess)))) (iter g…続きを読む
問題1.45 (define (average-damp f) (lambda (x) (average x (f x)))) (define (compose f g) (lambda (x) (f (g x)))) (define (repeated f n) (if (= n 1) (lambda (x) (f x)) (compose f (repeated f (- n 1))))) (…続きを読む
問題1.42 (define (compose f g) (lambda (x) (f (g x)))) ((compose square inc) 6) gosh> 49 問題1.43 (define (repeated f n) (if (= n 1) (lambda (x) (f x)) (compose f (repeated f (- n 1))))) ((repeated squ…続きを読む
問題1.40 (define tolerance 0.00001) (define (fixed-point f first-guess) (define (close-enough? v1 v2) (< (abs (- v1 v2)) tolerance)) (define (try guess) (let ((next (f guess))) (if (close-enough? gue…続きを読む
問題1.38 (define (cont-frac n d k) (define (iter i) (if (= i k) (/ (n i) (d i)) (/ (n i) (+ (d i) (iter (+ i 1)))))) (iter 1)) (define (iter-a-to-b f a b) (newline) (display a) (display " -> &qu…続きを読む
問題1.35 (define tolerance 0.00001) (define (fixed-point f first-guess) (define (close-enough? v1 v2) (< (abs (- v1 v2)) tolerance)) (define (try guess) (let ((next (f guess))) (if (close-enough? gue…続きを読む
1.3.3 一般的方法としての手続き 区間二分法による方程式の零点の探索 (define (search f neg-point pos-point) (let ((midpoint (average neg-point pos-point))) (if (close-enough? neg-point pos-point) midpoint (let ((test-value (f midpoi…続きを読む
局所変数 let の使い方 let は変数を特定の範囲内に束縛する。 変数の値は let の外側で計算される。 問題1.34 (define (f g) (g 2)) (f square) (square 2) (* 2 2) 4 (f (lambda (z) (* z (+ z 1)))) ((lambda (z) (* z (+ z 1))) 2) (* 2 (+ 2 1)) (* 2 3) …続きを読む
問題1.33 まず再帰的プロセスのものを書く。 (define (filtered-accumulate combiner null-value filter-pre term a next b) (cond ((> a b) null-value) ((filter-pre a) (combiner (term a) (filtered-accumulate combiner null-v…続きを読む
問題1.32 a 再帰的プロセスの accumulate (define (accumulate combiner null-value term a next b) (if (> a b) null-value (combiner (term a) (accumulate combiner null-value term (next a) next b)))) ;; sum (define…続きを読む