Question: i tried to implement the make-monitored procedure in Lisp Scheme here is the code and the problem i have (also show the origin question) code:

i tried to implement the make-monitored procedure in Lisp Scheme here is the code and the problem i have

(also show the origin question)

code:

(define (make-monitored f)

(let ((counter 0))

(lambda (x)

(cond

((eq? x 'how-many-calls?) counter)

((eq? x 'reset-count) (set! counter 0))

(else

(begin

(set! counter (+ counter 1))

(apply f x)))))))

test example :

The ``f'' may take any number of arguments. See the examples below.

You may have to use ``apply''.

 $ scheme48 > ,open random > (define a (make-random 1024)) ; no values returned > (a) 150946159 > (a) 44350967 > ,load ex13-monitor.scm > (define f (make-monitored a)) ; no values returned > (f) 88941411 > (f) 154130900 > (f 'how-many-calls?) 2 > (f) 1024 > (f) 159857230 > (f) 53732961 > (f 'how-many-calls?) 5 > (f 'reset-count) 0 > (f) 10059006 > (f 'how-many-calls?) 1 > (define plus (make-monitored +)) ; no values returned > (plus) 0 > (plus 1 2 3 4 5) 15 > (plus 'how-many-calls?) 2 > (plus 'reset-count) 0 > (plus 1 2) 3 > (plus 'how-many-calls?) 1 > ,exit $ 

problem:

when i (define f (make-monitored a)) and call (f) it showed:

the problem might show: assertion-violation: wrong number of arguments [tail-call] (#{procedure 8544 (unnamed in make-monitored)} '())

pls help me fix this code! (need to have the same result as test example)

origin question:

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 make-monitored that takes as input a procedure, f, that itself takes one input. The result returned by make-monitored is a third procedure, say mf, that keeps track of the number of times it has been called by maintaining an internal counter. If the input to mf is the special symbol how-many-calls?, then mf returns the value of the counter. If the input is the special symbol reset-count, then mf resets the counter to zero. For any other input, mf returns the result of calling f on that input and increments the counter. For instance, we could make a monitored version of the sqrt procedure:

(define s (make-monitored sqrt)) (s 100) 10 (s 'how-many-calls?) 1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!