問2
  > (define init-env (make-env))
  > (define-value! 'make-withdraw
      (list '*lambda* '(balance)
        '(lambda (amount)
           (if (>= balance amount)
               (begin (set! balance (- balance amount))
                      balance)
               "Insufficient funds"))
        init-env)
      init-env)
1 > (define make-withdraw-env (extend init-env '(balance) '(10000)))
1 > (define-value! 'w1
      (list '*lambda* '(amount)
        '(if (>= balance amount)
             (begin (set! balance (- balance amount))
                    balance)
             "Insufficient funds")
        make-withdraw-env)
      init-env)
2 > (define make-withdraw2-env (extend init-env '(balance) '(5000)))
2 > (define-value! 'w2
      (list '*lambda* '(amount)
        '(if (>= balance amount)
             (begin (set! balance (- balance amount))
                    balance)
             "Insufficient funds")
        make-withdraw2-env)
      init-env)
3 > (define w1-env (extend make-withdraw-env '(amount) '(1000)))
3 > (get 'balance w1-env)
  (balance . 10000)
3 > (get 'amount w1-env)
  (amount . 1000)
3 > (get 'balance w1-env)
  (balance . 10000)
3 > (get 'amount w1-env)
  (amount . 1000)
3 > (set!-value! 'balance 9000 w1-env)
3 > (get 'balance w1-env)
  (balance . 9000)
4 > (define w2-env (extend make-withdraw2-env '(amount) '(6000)))
4 > (get 'balance w2-env)
  (balance . 5000)
4 > (get 'amount w2-env)
  (amount . 6000)
5 > (define w12-env (extend make-withdraw-env '(amount) '(6000)))
5 > (get 'balance w12-env)
  (balance . 9000)
5 > (get 'amount w12-env)
  (amount . 6000)
5 > (get 'balance w12-env)
  (balance . 9000)
5 > (get 'amount w12-env)
  (amount . 6000)
5 > (set!-value! 'balance 3000 w12-env)
5 > (get 'balance w12-env)
  (balance . 3000)

一覧 前へ 次へ