To make this article get treatise and ask questions, reprint please indicate the source:
Http://blog.csdn.net/nomasp
Email and Skype:[email protected]
Facebook:https://www.facebook.com/yuwang.ke
CSDN Blog: http://blog.csdn.net/nomasp
Sina Weibo: http://weibo.com/nomasp
Exercise 3-7 Original
Exercise 3.7. Consider the bank account objects created to Make-account, with the password modification described in Exercise 3.3. Suppose that we banking system requires the ability to make joint accounts. Define a procedure make-joint that accomplishes this. Make-joint should take three arguments. The first is a password-protected account. The second argument must match the password with which the account is defined in order for the make-joint operation to PR Oceed. The third argument is a new password. Make-joint is to create a additional access to the original account using the new password. For example, if PETER-ACC are a bank account with password open-sesame and then
(define paul-acc (make-joint peter-acc‘open-sesame ‘rosebud))
Would allow one to make transactions on PETER-ACC using the name PAUL-ACC and the password rosebud. wish to modify your solution to exercise 3.3 to accommodate this new feature.
Analysis
Make-joint requires 3 parameters:
1. Password-protected account name
2. The original password that must match the password of the account
3. New Password
And it returns a procedure, so a lambda expression is required here, and it has a parameter mode and an incoming password parameter. In addition, in the output error message function also need a parameter, that is, it is not used, but for compatibility considerations, in the previous blog we have encountered this problem.
Code
( define (Make-jointOrigin-ACCOld-password New-password) ( define (Display-wrong-messageMSG) (Display"Incorrect password")) (Lambda (given-passwordmode) (if(eq?Given-password New-password) (Origin-ACCOld-passwordmode) display-wrong-message))); Value:make-joint
"SICP Exercise" 106 Exercise 3.7