]> git.rkrishnan.org Git - sicp.git/blob - src/sicp/ex3_3.rkt
Merge branch 'master' of github.com:vu3rdd/sicp
[sicp.git] / src / sicp / ex3_3.rkt
1 #lang racket
2
3 (define (make-account balance password)
4   (define (withdraw amount)
5     (if (>= balance amount)
6         (begin (set! balance (- balance amount))
7                balance)
8         "Insufficient funds"))
9   (define (deposit amount)
10     (set! balance (+ balance amount))
11     balance)
12   (define (dispatch given-password m)
13     (if (eq? given-password password)
14         (cond ((eq? m 'withdraw) (lambda (amt) (withdraw amt)))
15               ((eq? m 'deposit) (lambda (amt) (deposit amt)))
16               (else (error "Unknown request -- MAKE-ACCOUNT"
17                            m)))
18         (lambda (temp) "Incorrect password")))
19   dispatch)