【SICP练习】146 练习4.2

讨论了Louis尝试通过调整cond子句顺序以提升解释器效率的计划,并分析了该计划的缺陷。提出了一种修改语法的方法,使过程调用在识别阶段优先于其他表达式类型。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

练习4-2

原文

Exercise 4.2. Louis Reasoner plans to reorder the cond clauses in eval so that the clause for procedure applications appears before the clause for assignments. He argues that this will make the interpreter more efficient: Since programs usually contain more applications than assignments, definitions, and so on, his modified eval will usually check fewer clauses than the original eval before identifying the type of an expression.
a. What is wrong with Louis’s plan? (Hint: What will Louis’s evaluator do with the expression (define x 3)?)
b. Louis is upset that his plan didn’t work. He is willing to go to any lengths to make his evaluator recognize procedure applications before it checks for most other kinds of expressions. Help him by changing the syntax of the evaluated language so that procedure applications start with call. For example, instead of (factorial 3) we will now have to write (call factorial 3) and instead of (+ 1 2) we will have to write (call + 1 2).

分析

所有的序对都被当作应用。
因为都是以call开始,所以先用cdr取出exp,再分别用car和cdr取出operator和operands即可。

 (define (application? exp) (tagged-list? exp 'call)) 
 (define (operator exp) (cadr exp)) 
 (define (operands exp) (cddr exp)) 



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


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


版权声明:本文为 NoMasp柯于旺 原创文章,未经许可严禁转载!欢迎访问我的博客:http://blog.youkuaiyun.com/nomasp

转载于:https://my.oschina.net/nomasp/blog/503301

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值