【SICP练习】106 练习3.7
2015-03-11 18:59
225 查看
练习3-7
原文
Exercise 3.7. Consider the bank account objects created by make-account, with the password modification described in exercise 3.3. Suppose that our 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 was defined in order for the make-joint operation to proceed. The third argument is a new password. Make-joint is to create an additional access to the original account using the new password. For example, if peter-acc is a bank account with password open-sesame, then(define paul-acc (make-joint peter-acc 'open-sesame 'rosebud))
will allow one to make transactions on peter-acc using the name paul-acc and the password rosebud. You may wish to modify your solution to exercise 3.3 to accommodate this new feature.
分析
make-joint需要有3个参数:1.有密码保护的帐户名
2.必须与账号的密码匹配的原密码
3.新密码
而其会返回一个过程,因此在此处需要一个lambda表达式,并且其有一个参数mode和一个传入的密码参数。另外在输出错误信息的函数中也需要一个参数,即是它并不使用,只是出于兼容性的考虑,在前面的博客中我们也遇到过这种问题。
代码
(define (make-joint origin-acc old-password new-password) (define (display-wrong-message msg) (display "Incorrect password")) (lambda (given-password mode) (if (eq? given-password new-password) (origin-acc old-password mode) display-wrong-message))) ;Value: make-joint
感谢访问,希望对您有所帮助。 欢迎关注或收藏、评论或点赞。
为使本文得到斧正和提问,转载请注明出处:
http://blog.csdn.net/nomasp
相关文章推荐
- 【SICP练习】106 练习3.7
- 【SICP练习】38 练习1.43
- 【SICP练习】60 练习2.30
- 【SICP练习】76 练习2.47
- SICP 练习1.17
- 【SICP练习】88 练习2.60
- 【SICP练习】103 练习2.81-2.97
- 【SICP练习】105 练习3.5-3.6
- SICP 练习2.12 make-interval-percent
- 【SICP练习】109 练习3.22
- 【SICP练习】124 练习3.55
- SICP 练习2.34 多项式求值(horner规则)
- SICP-练习2.17
- 单向链表 练习3.7 多项式相乘
- 【SICP练习】4 练习1.8
- 【SICP练习】45 练习2.4
- 【SICP练习】127 练习3.58
- 【SICP练习】5 练习1.9
- 【SICP练习】42 练习2.1
- 【SICP练习】142 练习3.77