5.5.5. An Example of Compiled Code
Exercise 5.34

The essential difference between the code for iterative and recursive versions of factorial

Compile the iterative factorial procedure

(define (factorial n)
  (define (iter product counter)
    (if (> counter n)
        product
        (iter (* counter product)
              (+ counter 1))))
  (iter 1 1))

Annotate the resulting code, showing the essential difference between the code for iterative and recursive versions of factorial that makes one process build up stack space and the other run in constant stack space.


Nobody's finished this exercise yet. You'll be the first!


There are no comments yet.

Authentication required

You must log in to post a comment.

Login