博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【SICP练习】118 练习3.45【待完成】
阅读量:6240 次
发布时间:2019-06-22

本文共 1624 字,大约阅读时间需要 5 分钟。

练习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.

代码

临时发现有误,待完成。



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


为使本文得到斧正和提问,转载请注明出处:


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

转载于:https://www.cnblogs.com/NoMasp/p/4786083.html

你可能感兴趣的文章
tomcat6+awstats+win7配置成功
查看>>
对前面的自定义的toast制作拖拽效果,以及双击居中效果
查看>>
php 文件目录操作
查看>>
一个人的心态决定你的人生百分度
查看>>
lsyncd配置文件
查看>>
Java基础学习总结(7)——Object类
查看>>
OPEN SSH升级小结(针对SUSE REDHAT linux系统)
查看>>
Myeclipse优化配置
查看>>
RabbitMQ学习总结(7)——Spring整合RabbitMQ实例
查看>>
Notepad++ 快捷键大全
查看>>
Oracle统计求和
查看>>
在Android搭建简单的服务器
查看>>
智能合约编程/Dapp漏洞 --Unexpected Ether
查看>>
perl写的tcp连接数
查看>>
Windows 7自带截图工具技巧两则
查看>>
如何规划构建一套大型的Citrix桌面虚拟化架构 - 后记
查看>>
zencart lazyload插件
查看>>
delete和delete[] 的深度思考
查看>>
linux ifconfig命令
查看>>
截杀“WannaCrypt”,终结“永恒之蓝”!
查看>>