码迷,mamicode.com
首页 > 其他好文 > 详细

Exercise 1.9

时间:2014-09-15 17:19:29      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:io   os   ar   strong   for   sp   on   c   ad   

题目

  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 a) b),递归调用之后,还需要回到原函数进行inc计算,因此,是一个recursive process 

第二个函数:

  尾递归,是一个iterative process

Exercise 1.9

标签:io   os   ar   strong   for   sp   on   c   ad   

原文地址:http://www.cnblogs.com/linghuaichong/p/3973005.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!