首页 > 其他 > 详细

【SICP练习】117 练习3.44

时间:2015-03-26 23:38:40      阅读:291      评论:0      收藏:0      [点我收藏+]

练习3-44

原文

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

分析

题目中的transfer和第214页的exchange有一个很大的区别,前者不仅仅是计算余额的增减,还要计算它们的差值(difference),而在transfer中则不需要,只有一个amount,并且这个amount只是在每次进行增减余额之后更新。

transfer中,((from-account ‘withdraw) amount)和((to-account ‘deposit) amount)都已经进行了串行化因此都会逐个正确执行。但是在一方减少余额之后,另一方增加余额与其他的操作的先后顺序则不能肯定。但增减余额这两个操作都能始终被执行。

【SICP练习】117 练习3.44

原文:http://blog.csdn.net/nomasp/article/details/44654755

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!