Exercise 1.9 写道
Exercise 1.9. Each of the following two procedures defines a method for adding two positive integers in
terms of the procedures inc, which increments its argument by 1, and dec, which decrements its
argument by 1
(define (+ a b)(if (= a 0)b(inc (+ (dec a) b))))
(define (+ a b)(if (= a 0)b(+ (dec a) (inc b))))
写道
Using the substitution model, illustrate the process generated by each procedure in evaluating (+ 4 5).
Are these processes iterative or recursive?

这两个函数,分别使用两个用于自增(inc)和自减(dec)变量的方法组成,使用substitution model来展开它们计算(+ 4 5)的过程,并且指出他们的过程是迭代还是递归。

严格的按照过程展开即可

第一个:

(+ 4 5)
(inc (+ (dec 4) 5))
(inc (+ 3 5))
(inc (inc (+ (dec 3) 5)))
(inc (inc (+ 2 5)))
(inc (inc (inc (+ 1 5))))
(inc (inc (inc (inc (+ 0 5)))))
(inc (inc (inc (inc 5))))
(inc (inc (inc 6)))
(inc (inc 7))
(inc 8)
9

这个是一个递归过程

第二个方法:

(define (+ a b)(if (= a 0)b(+ (dec a) (inc b))))
(+ 4 5)
(+ 3 6)
(+ 2 7)
(+ 1 8)
(+ 0 9)
9

这个显然是迭代。

Exercise 1.9相关推荐

  1. 区别 eks_sport 和 exercise 有什么区别?看完你就清楚了!

    说到"运动"sport 这个单词应该是不少人看到"运动"的第一反应吧 sport /spɔ:t/ n.体育运动 例如:I'd say football is m ...

  2. 【DeepLearning】Exercise:Sparse Autoencoder

    Exercise:Sparse Autoencoder 习题的链接:Exercise:Sparse Autoencoder 注意点: 1.训练样本像素值需要归一化. 因为输出层的激活函数是logist ...

  3. (14)Why some people find exercise harder than others

    https://www.ted.com/talks/emily_balcetis_why_some_people_find_exercise_harder_than_others/transcript ...

  4. MIT 6.828 JOS学习笔记12 Exercise 1.9

    Lab 1中Exercise 9的解答报告 Exercise 1.9: 判断一下操作系统内核是从哪条指令开始初始化它的堆栈空间的,以及这个堆栈坐落在内存的哪个地方?内核是如何给它的堆栈保留一块内存空间 ...

  5. Exercise: Logistic Regression and Newton's Method

     Exercise: Logistic Regression and Newton's Method 题目地址: Exercise: Logistic Regression 题目概要:某个高中有8 ...

  6. Exercise: Linear Regression

     Exercise: Linear Regression 题目地址: http://openclassroom.stanford.edu/MainFolder/DocumentPage.php?c ...

  7. RDC Lent ifm IP Analysis Exercise

    RDC Lent ifm IP Analysis Exercise 文章目录 RDC Lent ifm IP Analysis Exercise Team Intro Introduction to ...

  8. Basketball Exercise CodeForces - 1195C(动态规划dp)

    Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exerci ...

  9. UFLDL教程:Exercise:Convolution and Pooling

    Deep Learning and Unsupervised Feature Learning Tutorial Solutions CNN的基本结构包括两层 其一为特征提取层,每个神经元的输入与前一 ...

  10. UFLDL教程: Exercise:Learning color features with Sparse Autoencoders

    Linear Decoders Deep Learning and Unsupervised Feature Learning Tutorial Solutions 以三层的稀疏编码神经网络而言,在s ...

最新文章

  1. Java项目:宠物商城系统(java+Springboot+Maven+mybatis+Vue+mysql)
  2. 场景解析--Pyramid Scene Parsing Network
  3. django-2 模板文件的加载
  4. SVN代码冲突解决方案小集合
  5. javascript 垃圾回收机制--分代式垃圾回收机制
  6. LintCode刷题——不同的二叉查找树I、II
  7. openssl生成https证书 (转)
  8. php判断除数是不是整数,五种js判断是否为整数类型方式
  9. linux 宽字符串,C语言中的多字节字符与宽字符
  10. web前端学习之HTML
  11. ofo败局中唯一赚到钱的只有他?当事人回应......
  12. Python3.x伪随机,元素重排,矩阵
  13. 华为悬红“奥林帕斯奖”,促进数据产业基础技术研究与生态建设
  14. 关于SQL的重复记录问题
  15. 飞思卡尔单片机c语言编程详解,主流16位单片机学习详解:飞思卡尔MC9S12G系列...
  16. 树莓派 串口如何使用 以及树莓派引脚对照表
  17. 【重要】股票收益互换
  18. KODI(原XBMC)二次开发完全解析(一)
  19. python微信群管理开禁言_微信群主怎么禁言别人?微信群怎么让群员禁言?
  20. 京东首页案例(流式布局)

热门文章

  1. 益聚星荣:DR钻戒,“一生只送一人”的暴利生意
  2. 网站新旧版切换,新旧版共存一段时间,域名不变
  3. SPARQL 使用教程
  4. Python 爬虫 数据提取
  5. 为什么1个字节(Byte)等8位(Bit)?
  6. 第26课:谈谈我对设计原则的思考
  7. tws蓝牙耳机p10双耳连接方法
  8. 如何打造一款游戏外挂
  9. NB-iot网络架构组成简介
  10. pandas实现对dataframe随机抽样、分层抽样