開発環境
- 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))の4(超言語的抽象)、4.1(超循環評価器)、4.1.3(評価器のデータ構造)、述語のテスト、手続きの表現、環境に対する操作、問題 4.11を解いてみる。
その他参考書籍
問題 4.11
コード(BBEdit)
sample.scm
;; 変更個所 (define (make-frame variables values) (map cons variables values)) (define (frame-variables frame) (map car frame)) (define (frame-values frame) (map cdr frame)) (define (add-binding-to-frame! var val frame) (set-cdr! frame (cons (cons var val) (cdr frame)))) (define f (make-frame '(a b c d) (list 1 2 3 4)))
入出力結果(Terminal, REPL(Read, Eval, Print, Loop))
1 ]=> f ;Value 2: ((a . 1) (b . 2) (c . 3) (d . 4)) 1 ]=> (frame-variables f) ;Value 3: (a b c d) 1 ]=> (frame-values f) ;Value 4: (1 2 3 4) 1 ]=> (add-binding-to-frame! 'e 5 f) ;Unspecified return value 1 ]=> f ;Value 2: ((a . 1) (e . 5) (b . 2) (c . 3) (d . 4)) 1 ]=> (frame-variables f) ;Value 5: (a e b c d) 1 ]=> (frame-values f) ;Value 6: (1 5 2 3 4)
0 コメント:
コメントを投稿