dispatch
many bank accounts, many operations
- procedure that makes accounts:
(define (make-account bal)(define (withdraw amt) (set! bal (- bal amt)) bal)(define (deposit amt) (set! bal (+ bal amt)) bal)(define (dispatch m) (cond ((eq? m ‘withdraw) withdraw) ((eq? m ‘deposit) deposit)))dispatch)
example of use
- (define a1 (make-account 50))
- ((a1 ‘deposit) 40)
- ((a1 ‘withdraw) 60)