-
Notifications
You must be signed in to change notification settings - Fork 0
/
3.04.scm
26 lines (23 loc) · 869 Bytes
/
3.04.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
(define (make-account balance account-password)
(define (withdraw amount)
(if (<= amount balance)
(begin (set! balance (- balance amount))
balance)
(error "Insufficient funds")))
(define (deposit amount)
(set! balance (+ balance amount))
balance)
(define (call-the-cops)
(error "Calling the cops..."))
(let ((fail-count 0))
(define (dispatch password m)
(if (eq? password account-password)
(begin (set! fail-count 0)
(cond ((eq? m 'withdraw) withdraw)
((eq? m 'deposit) deposit)
(else (error "Unknown request: MAKE-ACCOUNT" m))))
(begin (set! fail-count (+ 1 fail-count))
(if (>= fail-count 7)
(call-the-cops)
(lambda (amount) (error "Incorrect password"))))))
dispatch))