You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
17 lines
449 B
17 lines
449 B
2 years ago
|
|
||
|
Exercise 5.34: 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.
|