zoukankan      html  css  js  c++  java
  • 【SICP练习】118 练习3.45【待完成】

    练习3-45

    原文

    Exercise 3.45. Louis Reasoner thinks our bank-account system is unnecessarily complex and error-prone now that deposits and withdrawals aren’t automatically serialized. He suggests that make-accountand-serializer should have exported the serializer (for use by such procedures as serializedexchange) in addition to (rather than instead of) using it to serialize accounts and deposits as makeaccount did. He proposes to redefine accounts as follows:

     (define (make-account-and-serializer balance) 
        (define (withdraw amount)   
           (if (>= balance amount)     
               (begin (set! balance (- balance amount))                
                       balance)       
                "Insufficient funds")) 
        (define (deposit amount)  
           (set! balance (+ balance amount))
           balance) 
        (let ((balance-serializer (make-serializer)))   
           (define (dispatch m)  
              (cond ((eq? m 'withdraw) (balance-serializer withdraw))            
                    ((eq? m 'deposit) (balance-serializer deposit))            
                    ((eq? m 'balance) balance)    
                    ((eq? m 'serializer) balance-serializer)            
                    (else (error "Unknown request -- MAKE-ACCOUNT"                         
                                 m))))  
            dispatch))

    Then deposits are handled as with the original make-account:

    (define (deposit account amount) 
       ((account 'deposit) amount))

    Explain what is wrong with Louis’s reasoning. In particular, consider what happens when serializedexchange is called.

    代码

    临时发现有误,待完成。



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


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


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

  • 相关阅读:
    css3 animate 和关键帧 @-webkit-keyframes
    CSS3 线性渐变(linear-gradient)
    css3 transition平滑过渡
    css3 变形设计涂鸦墙
    css3 图片翻转效果
    溢出隐藏
    顺序表的实现
    数论学习
    从BF算法到kmp算法详解
    王红梅、胡明、王涛编著的《数据结构c++》(第二版)模板类链表超详细代码
  • 原文地址:https://www.cnblogs.com/NoMasp/p/4786083.html
Copyright © 2011-2022 走看看