Skip to content

Instantly share code, notes, and snippets.

@zestime
Created February 6, 2015 10:23
Show Gist options
  • Save zestime/3379c881a0dd9bd31937 to your computer and use it in GitHub Desktop.
Save zestime/3379c881a0dd9bd31937 to your computer and use it in GitHub Desktop.
(define (make-account balance key)
(define (withdraw amount)
(if (>= balance amount)
(begin (set! balance (- balance amount))
balance)
"Insufficient funds"))
(define (deposit amount)
(set! balance (+ balance amount))
balance)
(define (dispatch k m)
(if (eq? key k)
(cond ((eq? m 'withdraw) withdraw)
((eq? m 'deposit) deposit)
(else (error "Unknown request -- MAKE-ACCOUNT"
m)))
(error "Incorrect Password")))
dispatch)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment