another variant
one bank account, many operations
(define withdraw ‘unimplemented)
(define deposit ‘unimplemented)
(define (make-account bal) (begin (set! withdraw (lambda (amt) (set! bal (- bal amt)) bal)) (set! deposit (lambda (amt) (set! bal (+ bal amt)) bal))))
example of use
- (make-account 50)
- (deposit 40) ==ᢒ
- (withdraw 60) ==> 30
notes
- this coding style is a dangerous: must apply make-account before using ops
- used in problem set code