2017-01-01から1年間の記事一覧

3.3.1 可変リスト構造

Exercise 3.12 appendとappend!の挙動の違い 手続きの定義 ; xの一番最後の要素にyを付け加える (define (append x y) (if (null? x) y (cons (car x) (append (cdr x) y)) ) ) ; xの最後の要素をとってきて、そこに追加する (define (append! x y) (set-cdr…

3.2 評価の環境モデル

環境とは フレーム (frame) が並んだもの フレームとは 変数の名前 + 対応する値を結び付ける束縛 (binding)のセット 1つのフレームは任意の変数に対して 0or1 の束縛をもつ 外側の環境へのポインタを持つ ただしglobalは、外側の環境へのポインタを持たない…

3.2.4 内部定義

Exercise 3.11 (define (make-account balance) (define (withdraw amount) (if (>= balance amount) (begin (set! balance (- balance amount)) balance) "Insufficient funds")) (define (deposit amount) (set! balance (+ balance amount)) balance) (de…

3.2.3 局所状態の保管場所としてのフレーム

Exercise 3.10 (let ((⟨var⟩ ⟨exp⟩)) ⟨body⟩) は ((lambda (⟨var⟩) ⟨body⟩) ⟨exp⟩) と解釈される。 その場合を環境モデルを使って説明せよ。 (define W1 (make-withdraw 100)) (W1 50) (define W2 (make-withdraw 100)) 書き換えた場合の処理は (define (mak…