Skip to content

Instantly share code, notes, and snippets.

@zestime
Created February 6, 2015 10:32
Show Gist options
  • Save zestime/ab2faae85834fa438642 to your computer and use it in GitHub Desktop.
Save zestime/ab2faae85834fa438642 to your computer and use it in GitHub Desktop.
(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