開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Scheme (プログラミング言語)
- MIT/GNU Scheme (処理系)
計算機プログラムの構造と解釈(Gerald Jay Sussman(原著)、Julie Sussman(原著)、Harold Abelson(原著)、和田 英一(翻訳)、ピアソンエデュケーション、原書: Structure and Interpretation of Computer Programs (MIT Electrical Engineering and Computer Science)(SICP))の5(レジスタ計算機での計算)、5.4(積極制御評価機)、5.4.4(評価の実行)、評価器の性能監視、問題 5.30-b.を解いてみる。
その他参考書籍
問題 5.30-b.
修正、追加箇所。
コード(BBEdit)
eval.scm
;; (define (apply-primitive-procedure proc args) (let ((p (primitive-implementation proc))) (cond ((and (eq? p car) (not (pair? (car args)))) 'apply-primitive-procedure-error) ((and (eq? p /) (eq? (cadr args) 0)) 'apply-primitive-procedure-error) (else (my-apply p args))))) (define (apply-primitive-procedure-error? val) (eq? val 'apply-primitive-procedure-error)) ;;
コード(BBEdit)
eceval.scm
;; (list 'apply-primitive-procedure-error? apply-primitive-procedure-error?) ;; primitive-apply (assign val (op apply-primitive-procedure) (reg proc) (reg argl)) (test (op apply-primitive-procedure-error?) (reg val)) (branch (label primitive-apply-error)) (restore continue) (goto (reg continue)) primitive-apply-error (assign val (const primitive-apply-error)) (goto (label signal-error)) ;;
コード(BBEdit)
sample.scm
(load "./eval.scm") (load "./register.scm") (load "./eceval.scm") (start eceval)
入出力結果(Terminal, REPL(Read, Eval, Print, Loop))
$ scheme MIT/GNU Scheme running under MacOSX Type `^C' (control-C) followed by `H' to obtain information about interrupts. Copyright (C) 2011 Massachusetts Institute of Technology This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Image saved on Saturday October 26, 2013 at 11:02:50 PM Release 9.1.1 || Microcode 15.3 || Runtime 15.7 || SF 4.41 || LIAR/C 4.118 Edwin 3.116 1 ]=> (load "./sample.scm") ;Loading "./sample.scm"... ; Loading "eval.scm"... done ; Loading "register.scm"... ; Loading "eceval.scm"... done ;;; EC-Eval input: (/ 10 5) (total-pushes = 8 maximum-depth = 5) ;;; EC-Eval value: 2 ;;; EC-Eval input: (/ 10 0) primitive-apply-error ;;; EC-Eval input: (car '(1 2)) (total-pushes = 5 maximum-depth = 3) ;;; EC-Eval value: 1 ;;; EC-Eval input: (car 1) primitive-apply-error ;;; EC-Eval input: End of input stream reached. Moriturus te saluto. $
0 コメント:
コメントを投稿