Chapter 4, Metalinguistic Abstraction
Exercise 4.29
Time taken:
Non memoized time: 13
Memoized time: 0
Here, is the code i used in both versions:
1
2
3
4
5
6
7
8
;;; L-Eval input:
((lambda()
(define (fact n) (if (= n 1) 1 (* n (fact (- n 1)))))
(define (dummy b) (+ b b b b b b b b b b b b b b b b b b b b b b b b b b b b))
(dummy (fact 100))
'done))
;;; L-Eval value:
done
Code changes for Time:
1
2
3
4
5
6
7
8
9
10
11
12
(define (driver-loop)
(prompt-for-input input-prompt)
(let ((input (read)))
(define stime (get-universal-time))
(let ((output
(actual-value input the-global-environment)))
(newline)
(display (list "Time Taken: " (- (get-universal-time) stime)))
(newline)
(announce-output output-prompt)
(user-print output)))
(driver-loop))
output
This is similar as ex-4.27. There I already thought of the difference between memoized and non-memoized which this exercise elaborates now.
Memoized:
1
2
3
4
5
6
7
8
9
10
11
;;; L-Eval input:
(square (id 10))
;;; L-Eval value:
100
;;; L-Eval input:
count
;;; L-Eval value:
1
Non-memoized:
1
2
3
4
5
6
7
8
9
10
11
;;; L-Eval input:
(square (id 10))
;;; L-Eval value:
100
;;; L-Eval input:
count
;;; L-Eval value:
2