Friday, June 19, 2009

Ex-3.4

(define (make-account balance secret-passwd)
(define (withdraw amount)
(if (>= balance amount)
(begin (set! balance (- balance amount))
balance)
"Insufficient funds"))
(define (deposit amount)
(set! balance (+ balance amount))
balance)
(let ((counter 0))
(define (dispatch p m)
(if (eq? p secret-passwd)
(begin
(cond
((eq? m 'withdraw) withdraw)
((eq? m 'deposit) deposit)
(else (error "Unknown request -- MAKE-ACCOUNT"
m)))
(set! counter 0))
(begin
(set! counter (+ counter 1))
(if (> counter 7) "Call the cops"
"Incorrect Password"))))
dispatch))

No comments:

Post a Comment