Resource > SICP Exersise 3_2
Exersise 3.2
(define (make-monitored f)
(let ((counter 0))
(lambda (lis)
(if (equal? 'how-many-calls? lis)
counter
(begin
(set! counter (+ counter 1))
(f lis))))))
(use gauche.test)
(test-start "Exersise 3.2")
(define s (make-monitored sqrt))
(test* "exec" 10.0 (s 100))
(test* "count" 1 (s 'how-many-calls?))
(test* "count" 1 (s 'how-many-calls?))
(test* "exec" 10.0 (s 100))
(test* "count" 2 (s 'how-many-calls?))
(test-end)