diff --git a/3_3.rkt b/3_3.rkt index 6e4e1ab..65457c0 100644 --- a/3_3.rkt +++ b/3_3.rkt @@ -1,6 +1,7 @@ #lang sicp (define (make-account balance account-password) + (define bad-passwords 0) (define (withdraw amount) (if (>= balance amount) (begin (set! balance (- balance amount)) @@ -10,11 +11,20 @@ (begin (set! balance (+ balance amount)) balance)) + (define (call-the-cops) + (error "Call the cops")) + ;;(let ((bad-passwords 0)) (define (dispatch password m) (if (eq? password account-password) - (cond ((eq? m 'withdraw) withdraw) - ((eq? m 'deposit) deposit) - (else (error "Unknown request -- MAKE-ACCOUNT" - m))) - (error "Incorrect password"))) + (begin + (set! bad-passwords 0) + (cond ((eq? m 'withdraw) withdraw) + ((eq? m 'deposit) deposit) + (else (error "Unknown request -- MAKE-ACCOUNT" + m)))) + (begin + (set! bad-passwords (+ bad-passwords 1)) + (if (> bad-passwords 7) + (error "Call the cops") + (error "Incorrect password"))))) dispatch)