tags:

views:

133

answers:

2

I have the following code and would like to add a 'clear message that removes all the stored numbers from the internal list. How would I do this?

     (define (make-stat)
      (let ((values (list)))
        (lambda (op . args)
          (cond ((eq? op 'add)            
                 (set! values (cons (car args) values)))
                ((eq? op 'mean)
                 (if (null? values) 
                     (error "can't take mean of empty data set")
                     (mean values)))
                ((eq? op 'variance)
                 (if (null? values)
                     (error "can't take variance of empty data set")
                     (variance values)))
                (else (error "unknown op" op))))))
+1  A: 

Does

((eq? op 'clear)
 (set! values '()))

not work? I guess I don't understand where your stumbling block is.

Kyle Cronin
+1  A: 

This question is missing the "homework" tag.

jonrock