環境モデルの実装による再現
  > (define init-env (make-env))
1 > (define-value! 'fac
      (list '*lambda* '(n)
        '(begin (define (iter-fac product counter)
                  (if (> counter n)
                      product
                      (iter-fac (* product counter) (+ counter 1))))
                (iter-fac 1 1))
        init-env)
      init-env)
2 > (define fac-env (extend init-env '(n) '(1)))
2 > (define-value! 'iter-fac
      (list '*lambda* '(product counter)
        '(if (> counter n)
             product
             (iter-fac (* product counter) (+ counter 1)))
        fac-env)
      fac-env)
2 > (define iter-fac-env (extend fac-env '(product counter) '(1 1)))
2 > (get 'counter iter-fac-env)  ; (> counter n) の計算のため
  (counter . 1)
2 > (get 'n iter-fac-env)        ; (> counter n) の計算のため
  (n . 1)
2 > (get 'product iter-fac-env)  ; (* product counter) の計算のため
  (product . 1)
2 > (get 'counter iter-fac-env)  ; (* product counter) の計算のため
  (counter . 1)
2 > (get 'counter iter-fac-env)  ; (+ counter 1) の計算のため
  (counter . 1)
2 > (define iter-fac2-env (extend fac-env '(product counter) '(1 2)))
2 > (get 'counter iter-fac2-env) ; (> counter n) の計算のため
  (counter . 2)
2 > (get 'n iter-fac2-env)       ; (> counter n) の計算のため
  (n . 1)
2 > (get 'product iter-fac2-env)
  (product . 1)

一覧 前へ 次へ