Chapter 1, Building Abstractions with Procedures

Section - Procedures and the Processes They Generate

Exercise 1.9


Process generated by the first procedure:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
; procedure 
(define (+ a b)
  (if (= a 0)
      b
      (inc (+ (dec a) b))))
      
; process generated
(+ 4 5)
(inc (+ 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       

Process generated by second process:

1
2
3
4
5
6
7
8
9
10
11
12
13
; procedure 
(define (+ a b)
    (if (= a 0) 
        b
        (+ (dec a) (inc b))))      

; process generated
(+ 4 5)
(+ 3 6)
(+ 2 7)
(+ 1 8)
(+ 0 9)
9       

Clearly first procedure generates recursive process and second generates iterative process.