Recursive Execution ...

This time, our test (if (<= n 0) ...) is true and we return the value 1 as the value of (fact 0):

n = 1
n = 2
n = 3

Now the top stack frame has been popped off. We multiply 1 by the value of (fact 0) (also 1) and return 1 as the value of (fact 1).

Now (fact 1) = 1 and our stack looks like:

n = 2
n = 3

We multiply 2 by the value of (fact 1) and return 2 as the value of (fact 2):

n = 3

We multiply 3 by the value of (fact 2) and return 6 as the final value of (fact 3). Now the stack is empty.

The trace printout two pages above shows the argument values and return values.

Contents    Page-10    Prev    Next    Page+10    Index