"SICP Exercise" 106 Exercise 3.7

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.