2015/11/05
SICP 問題 3.2
(define (make-monitored f)
(let ((mf 0))
(lambda (in)
(cond ((eq? in 'how-many-calls?) mf)
((eq? in 'reset-count)
(set! mf 0))
(else (set! mf (+ 1 mf))
(f in))))))
gosh> (define s (make-monitored sqrt))
s
gosh> (s 100)
10
gosh> (s 'how-many-calls?)
1
gosh> (s 'reset-count)
0
gosh> (s 'how-many-calls?)
0