博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【SICP练习】145 练习4.1
阅读量:6877 次
发布时间:2019-06-26

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

练习4-1

原文

Exercise 4.1. Notice that we cannot tell whether the metacircular evaluator evaluates operands from left to right or from right to left. Its evaluation order is inherited from the underlying Lisp: If the arguments to cons in list-of-values are evaluated from left to right, then list-of-values will evaluate operands from left to right; and if the arguments to cons are evaluated from right to left, then list-ofvalues will evaluate operands from right to left.Write a version of list-of-values that evaluates operands from left to right regardless of the order of evaluation in the underlying Lisp. Also write a version of list-of-values that evaluates operands from right to left.

分析

如题中所说的,list-of-values的求值顺序由cons的参数而定。同时也要使用no-operands?来判断exps,如果为真则返回空。而左右之分,在let中的求值顺序可以决定。如果是从左到右就应该是先求值first而后求值rest,最后用cons来构造到一起即可。

代码

(define (list-of-values-l-to-r exps env)    (if (no-operands? exps)        '()        (let ((first (eval (first-operand exps) env)))          (let ((rest (list-of-values-l-to-r (rest-operands exps) env)))            (cons first rest)))))  (define (list-of-values-r-to-l exps env)    (if (no-operands? exps)        '()        (let ((rest (list-of-values-r-to-l (rest-operands exps) env)))          (let ((first (eval (first-operand exps) env)))            (cons first rest)))))



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


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


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

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

你可能感兴趣的文章
linux增加swap分区
查看>>
Android软键盘的显示与隐藏
查看>>
ThreadPool 线程池
查看>>
AWK 文件处理计数
查看>>
我的友情链接
查看>>
AI技术说:人工智能相关概念与发展简史
查看>>
eclipse启动失败
查看>>
(已解决!)精选30道Java笔试题解答
查看>>
【Python之旅】第七篇(三):使用Redis订阅服务
查看>>
linux远程桌面链接windows
查看>>
TrendMicro:新的APT***针对亚洲和欧洲政府组织,包括中国媒体机构
查看>>
C语言中sizeof与strlen区别2
查看>>
我的友情链接
查看>>
我的友情链接
查看>>
我的友情链接
查看>>
UIWebView加载html网页时使用缓存和清空缓存
查看>>
我的友情链接
查看>>
设计模式学习笔记(六)之策略模式(Strategy)
查看>>
python运行spark脚本程序
查看>>
我的友情链接
查看>>