計算機プログラムの構造と解釈[第2版]
(翔泳社)
ハロルド エイブルソン (著) ジュリー サスマン (著)
ジェラルド・ジェイ サスマン (著)
Harold Abelson (原著) Julie Sussman (原著)
Gerald Jay Sussman (原著) 和田 英一 (翻訳)
開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Scheme (プログラミング言語)
- Gauche (処理系)
計算機プログラムの構造と解釈[第2版](ハロルド エイブルソン (著)、ジュリー サスマン (著)、ジェラルド・ジェイ サスマン (著)、Harold Abelson (原著)、Julie Sussman (原著)、Gerald Jay Sussman (原著)、和田 英一 (翻訳)、翔泳社、原書: Structure and Interpretation of Computer Programs (MIT Electrical Engineering and Computer Science)(SICP))の3(標準部品化力、オブジェクトおよび状態)、3.2(評価の環境モデル)、3.2.3(局所変数の入れ物としてのフレーム)、問題 3.10.を解いてみる。
その他参考書籍
- Instructor's Manual to Accompany Structure & Interpretation of Computer Programs
- プログラミングGauche (Kahuaプロジェクト (著), 川合 史朗 (監修), オライリージャパン)
問題 3.10.
環境構造。
(define (make-withdraw initial-amount)
(let ((balance initial-amount))
(lambda (amount)
(if (>= balance amount)
(begin (set! balance (- balance amount))
balance)
"Insufficient funds"))))
;; 大域環境
make-withdraw
;; パラメータ
intial-amount
;; 本体
((lambda (balance)
(lambda (amount)
(if (>= balance amount)
(begin (set! balance (- balance amount))
balance)
"Insufficient funds")))
initial-amount)
;; -> 大域環境
;; E1 -> 大域環境
initial-amount: 100
;; E2 -> E1
balance: initial-amount
;; 大域環境
W1
;; パラメーター
amount
;; 本体
(if (>= balance amount)
(begin (set! balance (- balance amount))
balance)
"Insufficient funds")
;; -> E2
;; 大域環境
(W1 50)
;; E3 -> E2
amount: 50
(if (>= initial-amount amount)
(begin (set! initial-amount (- initial-amount amount))
initial-amount)
"Insufficient funds")
initial-amount: 50
;; E4 -> 大域環境
initial-amount: 100
;; E5 -> E4
balance: initial-amount
;; 大域環境
W2
;; パラメーター
amount
;; 本体
(if (>= balance amount)
(begin (set! balance (- balance amount))
balance)
"Insufficient funds")
;; -> E5
0 コメント:
コメントを投稿