[plt-scheme] Question about science collection / histogram

From: Doug Williams (m.douglas.williams at gmail.com)
Date: Mon Jan 28 17:34:59 EST 2008

It looks like sloppy code on my part.  I assume it worked in some previous
version, but I will change the exit call to take an argument.  I assume
something downstream wants a value now.  I'll release a new version this
evening.

Doug

On Mon, Jan 28, 2008 at 3:20 PM, Vincent Rayappa <vrayappa at gmail.com> wrote:

> 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.
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20080128/a724cc9c/attachment.html>

Posted on the users mailing list.