開発環境
- OS X Lion - Apple(OS)
- Emacs、BBEdit - Bare Bones Software, Inc. (Text Editor)
- プログラミング言語: MIT/GNU Scheme
計算機プログラムの構造と解釈(Gerald Jay Sussman(原著)、Julie Sussman(原著)、Harold Abelson(原著)、和田 英一(翻訳)、ピアソンエデュケーション、原書: Structure and Interpretation of Computer Programs (MIT Electrical Engineering and Computer Science)(SICP))の3(標準部品化力, オブジェクトおよび状態)、3.2(評価の環境モデル)、3.2.3(局所変数の入れ物としてのフレーム)の問題 3.10を解いてみる。
その他参考書籍
問題 3.10
コード(BBEdit)
sample.scm
(define (make-withdraw initial-amount) ((lambda (balance) (lambda (amount) (if (>= balance amount) (begin (set! balance (- balance amount)) balance) "Insufficient funds"))) initial-amount)) (define W1 (make-withdraw 100)) (define W2 (make-withdraw 100))
入出力結果(Terminal, REPL(Read, Eval, Print, Loop))
1 ]=> (W1 50) ;Value: 50 1 ]=> (W2 10) ;Value: 90
大域環境でmake-withdrawを定義した結果。
(define W1 (make-withdraw 100))の評価の結果。
手続きオブジェクトW1を作用させて作り出される環境。
W1呼び出し後の環境。
(define W2 (make-withdraw 100))を使いに番目のオブジェクトを作り出した結果。
0 コメント:
コメントを投稿