zoukankan      html  css  js  c++  java
  • 【SICP练习】117 练习3.44

    练习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)都已经进行了串行化因此都会逐个正确执行。但是在一方减少余额之后,另一方增加余额与其他的操作的先后顺序则不能肯定。但增减余额这两个操作都能始终被执行。



    感谢访问,希望对您有所帮助。 欢迎关注或收藏、评论或点赞。


    为使本文得到斧正和提问,转载请注明出处:
    http://blog.csdn.net/nomasp


    版权声明:本文为 NoMasp柯于旺 原创文章,如需转载请联系本人。

  • 相关阅读:
    关于排列问题的一系列归类
    [翻译] 服务定位器是反模式
    [翻译] Autofac 入门文档
    关系,表和封闭世界假定
    Elasticsearch实现类似 like '?%' 搜索
    LVS + keepalived(DR) 实战
    kafka集群中常见错误的解决方法:kafka.common.KafkaException: Should not set log end offset on partition
    Elasticsearch1.7服务搭建与入门操作
    Ubuntu下安装Tomcat7
    VB编程技巧推荐
  • 原文地址:https://www.cnblogs.com/NoMasp/p/4786084.html
Copyright © 2011-2022 走看看