Chapter 3, Modularity, Objects, and State

Exercise 3.2


1
2
3
4
5
6
7
8
9
10
11
12
13
#lang sicp

(define (make-monitored proc)
   (let ((calls-count 0))
      (lambda (arg)
         (cond
            ((equal? arg 'howmany-calls?) calls-count)
            ((equal? arg 'reset-count) (set! calls-count 0) calls-count)
            (else (set! calls-count (+ calls-count 1)) (proc arg))
         )
      )
   )
)