2013年7月25日木曜日

開発環境

計算機プログラムの構造と解釈(Gerald Jay Sussman(原著)、Julie Sussman(原著)、Harold Abelson(原著)、和田 英一(翻訳)、ピアソンエデュケーション、原書: Structure and Interpretation of Computer Programs (MIT Electrical Engineering and Computer Science)(SICP))の3(標準部品化力, オブジェクトおよび状態)、3.3(可変データでのモデル化)、3.3.5(制約の拡散)、制約システムの使い方、制約システムの実装、コネクタの表現の問題 3.36、問題 3.37を解いてみる。

その他参考書籍

問題3.36

評価前の環境図。

評価後の環境図。(代入後)

問題3.37

コード(BBEdit)

sample.scm

(define (c- x y)
  (let ((z (make-connector)))
    (adder x z y)
    z))

(define (c* x y)
  (let ((z (make-connector)))
    (multiplier x y z)
    z))

(define (c/ x y)
  (let ((z (make-connector)))
    (multiplier z y x)
    z))

(define (cv v)
  (let ((x (make-connector)))
    (constant v x)
    x))

入出力結果(Terminal, REPL(Read, Eval, Print, Loop))

1 ]=> (probe "c" c)

;Value 2: #[compound-procedure 2 me]

1 ]=> (probe "f" f)

;Value 3: #[compound-procedure 3 me]

1 ]=> (set-value! c 0 'user)

Probe: c = 0
Probe: f = 32
;Value: done

1 ]=> (forget-value! c 'user)

Probe: c = ?
Probe: f = ?
;Value: done

1 ]=> (set-value! f 32 'user)

Probe: f = 32
Probe: c = 0
;Value: done

1 ]=> (forget-value! f 'user)

Probe: f = ?
Probe: c = ?
;Value: done

1 ]=> (set-value! c 10 'user)

Probe: c = 10
Probe: f = 50
;Value: done

1 ]=> (forget-value! c 'user)

Probe: c = ?
Probe: f = ?
;Value: done

1 ]=> (set-value! c 20 'user)

Probe: c = 20
Probe: f = 68
;Value: done

1 ]=> (forget-value! c 'user)

Probe: c = ?
Probe: f = ?
;Value: done

1 ]=> (set-value! f 0 'user)

Probe: f = 0
Probe: c = -160/9
;Value: done

1 ]=> (forget-value! f 'user)

Probe: f = ?
Probe: c = ?
;Value: done

1 ]=> (set-value! f 0.0 'user)

Probe: f = 0.
Probe: c = -17.77777777777778
;Value: done

1 ]=> (forget-value! f 'user)

Probe: f = ?
Probe: c = ?
;Value: done

1 ]=> (set-value! f 10.0 'user)

Probe: f = 10.
Probe: c = -12.222222222222221
;Value: done

1 ]=> (forget-value! f 'user)

Probe: f = ?
Probe: c = ?
;Value: done

1 ]=> (set-value! f 20.0 'user)

Probe: f = 20.
Probe: c = -6.666666666666666
;Value: done

1 ]=> (forget-value! f 'user)

Probe: f = ?
Probe: c = ?
;Value: done

1 ]=> (set-value! f 50.0 'user)

Probe: f = 50.
Probe: c = 10.
;Value: done

0 コメント:

コメントを投稿