练习4-7

原文

Exercise 4.7. Let* is similar to let, except that the bindings of the let variables are performed sequentially from left to right, and each binding is made in an environment in which all of the preceding bindings are visible. For example

(let* ((x 3)      (y (+ x 2))  (z (+ x y 5)))  (* x z))

returns 39. Explain how a let* expression can be rewritten as a set of nested let expressions, and write a procedure let*->nested-lets that performs this transformation. If we have already implemented let (exercise 4.6) and we want to extend the evaluator to handle let*, is it sufficient to add a clause to eval whose action is

(eval (let*->nested-lets exp) env)

or must we explicitly expand let* in terms of non-derived expressions?

分析

这道题和上一道非常相似,抓住题中的要点就会迎刃而解啦。那就是说从左至右求值,那么我们能够用list和car以及cdr来完毕,核心思想是用递归。不断的向右边推进,直到exp为空,此时就返回body。然后结束构造。至于tagged-list?这些和上一题都是一样的。

代码


(define (let*?

expr) (tagged-list? expr 'let*)) (define (let*-body expr) (caddr expr)) (define (let*-exp expr) (cadr expr)) (define (let*->nested-lets expr) (let ((exp (let*-exp expr)) (body (let*-body expr))) (defien (make-lets exprs) (if (null? exprs) body (list 'let (list (car exprs)) (make-lets (cdr exprs))))) (make-lets exp)))



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

转载于:https://www.cnblogs.com/zsychanpin/p/7150634.html

【SICP练习】151 练习4.7相关推荐

  1. csapp 、sicp 、深入理解计算机系统、 计算机程序的构造和解释

    CSAPP 第一版的英文版 深入理解计算机系统第一版中文版  这个是csdn账号  这里上传文件大小在10M以内  这个pdf是19+M的 深入理解计算机系统第二版的中文版下载 第一版英文版的介绍原书 ...

  2. SICP 习题 (2.7) 解题总结 : 定义区间数据结构

    SICP 习题 2.7 開始属于扩展练习,能够考虑不做,对后面的学习没什么影响.只是,假设上面的使用过程表示序对,还有丘奇计数你都能够理解的话,完毕这些扩展练习事实上没什么问题. 习题2.7是要求我们 ...

  3. 成功解决sklearn\preprocessing\label.py:151: DeprecationWarning: The truth value of an empty array is amb

    成功解决sklearn\preprocessing\label.py:151: DeprecationWarning: The truth value of an empty array is amb ...

  4. 成功解决preprocessing\label.py:151: DeprecationWarning: The truth value of an empty array is ambiguous.

    成功解决preprocessing\label.py:151: DeprecationWarning: The truth value of an empty array is ambiguous. ...

  5. java 151建议_编写高质量代码改善java程序的151个建议——导航开篇

    前言 系列文章: 下个星期度过这几天的奋战,会抓紧java的进阶学习.听过一句话,大哥说过,你一个月前的代码去看下,惨不忍睹是吧.确实,人和代码一样都在成长,都在变好当中.有时候只是实现功能的编程,长 ...

  6. SICP学习笔记(1.1.4~1.1.5)

        SICP学习笔记(1.1.4~1.1.5)                                                                           ...

  7. 编写高质量代码:改善Java程序的151个建议(第1章:JAVA开发中通用的方法和准则___建议1~5)...

                 The reasonable man adapts himself to the world; The unreasonable one persists in trying ...

  8. leetcode 557. Reverse Words in a String III 、151. Reverse Words in a String

    557. Reverse Words in a String III 最简单的把空白之间的词反转 class Solution { public:string reverseWords(string ...

  9. 企业双11业绩增长156% 、成交额突破151亿元...... 这背后是阿里云数据中台的场景赋能

    红星美凯龙天猫数字化卖场累计成交金额突破151.52亿元:杜蕾斯全网销售额突破1.7亿元,天猫官方旗舰店销售额同比增长105%:滴露全网销售额突破1.8亿元,天猫官方旗舰店销售额同比增长156%:波司 ...

最新文章

  1. 1哈哈欢迎使用CSDN-markdown编辑器
  2. 51nod 1513-3的幂的和(费马小定理+快速幂)
  3. 代码是写给人看的,请C/C++过来的程序员们多学习软件工程
  4. 递归概念分类注意事项
  5. Intel超线程技术 Hyper-Threading Technology (3) - 处理器资源与超线程(复制的资源)
  6. Laravel——通过邮件找回密码
  7. MFC控件重叠显示问题
  8. 1384. 按年度列出销售总额
  9. 二叉搜索树 根据前序序列求中序序列
  10. ROS NOETIC 思岚激光雷达A2M8启动历程
  11. Privates下载
  12. Android数据库更新并保留原来数据的实现
  13. Camera测试-- ITS测试
  14. 神经网络中单层神经元表示逻辑运算
  15. 白鹭引擎王泽:重度H5游戏性能优化技巧
  16. Java毕业设计 社区疫情防控管理系统
  17. redis数据类型总结
  18. 安全绳使用方法图解_安全带和安全绳的正确使用方法
  19. python数字小游戏
  20. 他两次都没感动CCTV,却真正感动了中国

热门文章

  1. 微信防撤回python代码_python实现微信防撤回神器
  2. python复数运算程序_python复数-python,复数
  3. 华为新系统鸿蒙效果,19款华为手机内测新系统,流畅度比肩苹果iOS,优先体验鸿蒙OS...
  4. 二进制安装mysql集群_实战mysql集群搭建(一)--centos7下二进制安装mysql-5.6
  5. jax-ws使用教程_JAX-WS教程
  6. java多线程 线程安全_Java中的线程安全
  7. Android CoordinatorLayout
  8. Hibernate会话工厂
  9. 什么是运营?与产品的关系是怎样的?
  10. 雨课堂知识点总结(七)