I wrote a relatively simple bank account function, however when I try to run it I get an TypeError and I'm not sure to why? It's straight out of SICP so the solution is readily available, I just want to understand why my answer produces that error. Any thoughts? Here is my code:
(define (make-password-account balance password)
(define (withdraw amount)
(if (>= balance amount)
(begin (set! balance (- balance amount))
balance)
"Insufficient Funds"))
(define (deposit amount)
(set! balance (+ balance amount))
balance)
(define (dispatch users-guess-at-password m)
(if (eq? users-guess-at-password password)
(cond ((eq? m 'withdraw) withdraw)
((eq? m 'deposit) deposit)
(else (error "Unknown Request --make-account" m)))
"INVALID PASSWORD"))
dispatch)
Here is the relevant interpreter inputs and outputs from the interpreter:
..loaded function...
>(define acc (make-password-account 100 'secret))
acc
>((acc 's 'withdraw) 2)
;Stack Trace:
0 TypeError: The object "Invalid Password" is not applicable.
1 ((acc (quote s) (quote withdraw) 2)