Consider the bank account objects created by
, with the password modification described in exercise
. Suppose that our banking system requires the ability to make joint accounts. Define a procedure
that accomplishes this.
should take three arguments. The first is a password-protected account. The second argument must match the password with which the account was defined in order for the
operation to proceed. The third argument is a new password.
is to create an additional access to the original account using the new password. For example, if
is a bank account with password
(define paul-acc (make-joint peter-acc 'open-sesame 'rosebud))
will allow one to make transactions on
using the name
and the password
. You may wish to modify your solution to exercise
to accommodate this new feature.
There are no comments yet.
You must log in to post a comment.Login
(define (make-account balance secret) (define (withdraw amount) (if (>= balance amount) (begin (set! balance (- balance amount)) balance) "Insufficient funds")) (define (deposit amount) (set! balance (+ balance amount)) balance) (define (dispatch key m) (cond ((eq? key secret) (cond ((eq? m 'withdraw) withdraw) ((eq? m 'deposit) deposit) (else (error "Unknown request -- MAKE-ACCOUNT" m)))) (else (error "Wrong password")))) dispatch) (define peter-acc (make-account 100 'secret-password)) (define paul-acc (make-joint peter-acc 'secret-password 'rosebud)) (check-equal? ((peter-acc 'secret-password 'deposit) 10) 110) (check-equal? ((paul-acc 'rosebud 'deposit) 10) 120) (check-equal? ((peter-acc 'secret-password 'withdraw) 20) 100) (check-equal? ((paul-acc 'rosebud 'withdraw) 85) 15)