bank account example (2)
many bank accounts, one operation
- (define (make-withdraw bal) (lambda (i) (set! bal (- bal i)) bal))
- (define w1 (make-withdraw 100))
- (define w2 (make-withdraw 100))
- (w1 10) ==> 90
- (w1 10) ==> 80
- (w2 10) ==> 90
note
- w1 and w2 are different procedures: same code but different environments!