(set! load-noisily? #t) ; Bank account objects in Scheme (define (newaccount b) ; local procedures (define (withdraw a) (begin (set! b (- b a)) b)) (define (deposit a) (begin (set! b (+ b a)) b)) ; (define (inquiry) b) (define inquiry (lambda () b)) (define (interface method) (cond ((equal? method 'withdraw) withdraw) ((equal? method 'deposit) deposit) ((equal? method 'inquiry) (inquiry)) ; subtlety here (else 'error))) ; body of newaccount returns the interface interface) (define myaccount (newaccount 100)) (define youraccount (newaccount 200)) (myaccount 'inquiry) ((myaccount 'withdraw) 40) ((youraccount 'deposit) 100)