Number of procedure calls
In software-testing applications, it is useful to be able to count the number of times a given procedure is called during the course of a computation. Write a procedure
that takes as input a procedure,
, that itself takes one input. The result returned by
is a third procedure, say
, that keeps track of the number of times it has been called by maintaining an internal counter. If the input to
is the special symbol
, then mf returns the value of the counter. If the input is the special symbol reset-count, then
resets the counter to zero. For any other input,
returns the result of calling
on that input and increments the counter. For instance, we could make a monitored version of the
(define s (make-monitored sqrt)) (s 100) 10 (s 'how-many-calls?) 1
Nobody's finished this exercise yet. You'll be the first!
There are no comments yet.
You must log in to post a comment.Login