SICP exercise 1.09

From Drewiki

Jump to: navigation, search

Problem

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.

 

Using the substitution model, illustrate the process generated by each procedure in evaluating (+ 4 5). Are these processes iterative or recursive?

Solution

Using substitution to evaluate (+ 4 5) with the first procedure, we get:

 

The first procedure generates a recursive process.

Using substitution to evalute (+ 4 5) with the second procedure, we get:

 

The second procedure generates an interative process.

Personal tools