3.4 Exercise 3.4
I also shouldn’t need to mention that this is not a robust way
to deal with possible attempted account theft.
(define (make-account balance password) | (define incorrect-count 0) | (define (withdraw amount) | (if (>= balance amount) | (begin (set! balance (- balance amount)) | balance) | "Insufficient funds")) | (define (deposit amount) | (if (>= amount 0) | (begin (set! balance (+ balance amount)) | balance) | "Must deposit a non-negative amount")) | (define (dispatch p m) | (if (eq? p password) | (cond ((eq? m 'withdraw) withdraw) | ((eq? m 'deposit) deposit) | (else (error "Unknown request -- MAKE-ACCOUNT" m))) | (begin | (set! incorrect-count (+ incorrect-count 1)) | (if (> incorrect-count 7) (call-the-cops)) | (lambda args "Incorrect password")))) | dispatch) |
|