44 lines
1009 B
Scheme
44 lines
1009 B
Scheme
(load "shared/util")
|
|
(load "shared/sicp-load-eceval-compiler")
|
|
(load "shared/sicp-compiler")
|
|
|
|
|
|
(display "\nex-5.45 - factorial-stack-usage-comparison\n")
|
|
|
|
;(compile-and-go
|
|
; '(begin
|
|
; (define (factorial n)
|
|
; (if (= n 1)
|
|
; 1
|
|
; (* (factorial (- n 1)) n)))
|
|
; (factorial 10)))
|
|
|
|
; a.
|
|
|
|
; | (factorial 10) | pushes | depth |
|
|
; | -------------- | ------ | ------ |
|
|
; | machine | 18 | 18 |
|
|
; | compiled | 56 | 29 |
|
|
; | evaluator | 310 | 35 |
|
|
|
|
; | (factorial 20) | pushes | depth |
|
|
; | -------------- | ------ | ------ |
|
|
; | machine | 38 | 38 |
|
|
; | compiled | 116 | 59 |
|
|
; | evaluator | 630 | 65 |
|
|
|
|
; pushes(compiled/machine) = 3
|
|
; depth(compiled/machine) = 1.5
|
|
|
|
; pushes(evaluator/compiled) = 5.5
|
|
; depth(evaluator/compiled) = 1.2
|
|
|
|
; b. Use special handling for primitive procedures from exercise 5.38.
|
|
|
|
(display "[answered]\n")
|
|
|
|
(display "\nex-5.46 - fibo-stack-usage-comparison\n")
|
|
|
|
|
|
(display "\nex-5.47\n")
|