[plt-scheme] Question about science collection / histogram

From: Vincent Rayappa (vrayappa at gmail.com)
Date: Mon Jan 28 17:20:16 EST 2008

I would like to use the histogram module of the science collection to
generate histograms with custom ranges.

I tried:

(define h1 (make-histogram 4))
(set-histogram-ranges! h '#(0.0 1.0 2.0 4.0 16.0))

So far so good, but when I try to add a value like this:

(histogram-increment! h 5)

I get this error:

context expected 1 value, received 0 values
.../histogram.ss:219:10: (call/ec (lambda (exit) (if (< x (....))
(exit)) ((letrec-values ((....)) doloop) 0)))
[unknown source]: (void?31 (val (histogram?29 histogram?27) (real?30 real?28)))

Any idea what is going on?

The function is defined like this:

  ;; Increment the bin corresponding to the x value by one.

  (define (histogram-increment! h x)
    (let ((n (histogram-n h))
          (ranges (histogram-ranges h))
          (bins (histogram-bins h))
          (uniform-ranges? (histogram-ranges-uniform? h)))
      (if uniform-ranges?
          ;; Compute bin
          (let ((i (inexact->exact
                    (floor (/ (- x (vector-ref ranges 0))
                              (/ (- (vector-ref ranges n)
                                    (vector-ref ranges 0))
                                 n))))))
            (if (<= 0 i (- n 1))
                (vector-set! bins i
                             (+ (vector-ref bins i) 1))))
          ;; Search for bin
          (let/ec exit ;; <---------- line #219
            (if (< x (vector-ref ranges 0))
                (exit))
            (do ((i 0 (+ i 1)))
              ((= i n) (void))
              (if (< x (vector-ref ranges (+ i 1)))
                  (begin
                    (vector-set! bins i
                                 (+ (vector-ref bins i) 1))
                    (exit))))))))


Many Thanks,
Vincent.


Posted on the users mailing list.