How do I clear the internal list in the diagram?

I have the following code and want to add a "clear message" that removes all stored numbers from the internal list. How should I do it?

     (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))))))

      

0


source to share


1 answer


whether

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

      



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

+2


source







All Articles