Created
February 6, 2015 10:32
-
-
Save zestime/ab2faae85834fa438642 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (make-account balance key) | |
(let ((try 0)) | |
(define (withdraw amount) | |
(if (>= balance amount) | |
(begin (set! balance (- balance amount)) | |
balance) | |
"Insufficient funds")) | |
(define (deposit amount) | |
(set! balance (+ balance amount)) | |
balance) | |
(define (call-the-cops w) (error "Hit the floor!")) | |
(define (dispatch k m) | |
(if (eq? key k) | |
(begin (set! try 0) | |
(cond ((eq? m 'withdraw) withdraw) | |
((eq? m 'deposit) deposit) | |
(else (error "Unknown request -- MAKE-ACCOUNT" | |
m)))) | |
(begin (set! try (inc try)) | |
(if (> try 7) call-the-cops (lambda (s) "Incorrect Password"))))) | |
dispatch)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment