Exercise 3.44: Consider the problem of
transferring an amount from one account to another. Ben Bitdiddle claims that
this can be accomplished with the following procedure, even if there are
multiple people concurrently transferring money among multiple accounts, using
any account mechanism that serializes deposit and withdrawal transactions, for
example, the version of make-account in the text above.
(define
(transfer from-account to-account amount)
((from-account 'withdraw) amount)
((to-account 'deposit) amount))
Louis Reasoner claims that there is a problem here, and that we need to use a
more sophisticated method, such as the one required for dealing with the
exchange problem. Is Louis right? If not, what is the essential difference
between the transfer problem and the exchange problem? (You should assume that
the balance in from-account is at least amount.)
练习 3.44:考虑将一定金额从一个账户转账到另一个账户的问题。Ben Bitdiddle 声称,即使有多人同时在多个账户之间并发转账,只要使用一种能对存款和取款事务加以串行化的账户机制(例如正文中的 make-account 版本),下面的过程就足以完成这一任务:
(define
(transfer from-account to-account amount)
((from-account 'withdraw) amount)
((to-account 'deposit) amount))
Louis Reasoner 认为此处存在问题,需要采用更复杂的方法,比如处理交换问题所需的那种方法。Louis 说得对吗?若不对,转账问题与交换问题的本质区别是什么?(可以假设 from-account 中的余额至少为 amount。)
(define
(transfer from-account to-account amount)
((from-account 'withdraw) amount)
((to-account 'deposit) amount))