3 (define (make-account balance password)
4 (define (withdraw amount)
5 (if (>= balance amount)
6 (begin (set! balance (- balance amount))
9 (define (deposit amount)
10 (set! balance (+ balance amount))
12 (let ((bad-password-count 0))
13 (define (dispatch given-password m)
14 (if (eq? given-password password)
15 (cond ((eq? m 'withdraw) (lambda (amt) (withdraw amt)))
16 ((eq? m 'deposit) (lambda (amt) (deposit amt)))
17 (else (error "Unknown request -- MAKE-ACCOUNT"
21 (set! bad-password-count (+ bad-password-count 1))
22 (if (>= bad-password-count 7)
23 "Something is wrong. Calling 911..."
24 "Incorrect password")))))
29 > (define acc (make-account 100 'secret-password))
30 > ((acc 'secret-password 'withdraw) 40)
32 > ((acc 'some-other-password 'deposit) 50)
34 > ((acc 'some-other-password 'deposit) 50)
36 > ((acc 'some-other-password 'deposit) 50)
38 > ((acc 'some-other-password 'deposit) 50)
40 > ((acc 'some-other-password 'deposit) 50)
42 > ((acc 'some-other-password 'deposit) 50)
44 > ((acc 'some-other-password 'deposit) 50)
45 "Something is wrong. Calling 911..."