灯下 登录
计算机科学 / SICP / 3.1.3 The Costs of Introducing Assignment

Exercise 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.

练习 3.7:考虑由 make-account 创建的银行账户对象,带有练习 3.3 中描述的密码修改。假设我们的银行系统需要支持联名账户。定义一个过程 make-joint 来实现这一功能。make-joint 应接受三个参数:第一个是受密码保护的账户;第二个参数必须与创建该账户时所用的密码匹配,make-joint 操作才能继续;第三个参数是一个新密码。make-joint 要用新密码为原账户创建一个额外的访问入口。例如,若 peter-acc 是密码为 open-sesame 的银行账户,则

(define paul-acc
(make-joint peter-acc
'open-sesame
'rosebud))

将允许用名称 paul-acc 和密码 rosebud 对 peter-acc 进行交易。你可能需要修改练习 3.3 的解答来适配这一新功能。

Racket #lang sicp
(define paul-acc
 (make-joint peter-acc
 'open-sesame
 'rosebud))