局所変数 (Local Variable) の書き換え
(define (make-withdraw balance)
  (lambda (amount)
    (if (>= balance amount)
        (begin (set! balance (- balance amount))
               balance)
        "Insufficient funds")))
1 > (define w1 (make-withdraw 10000))
2 > (define w2 (make-withdraw 5000))
3 > (w1 1000)
  9000
4 > (w2 6000)
  "Insufficient funds"
5 > (w1 6000)
  3000

一覧 前へ 次へ