[plt-scheme] Question about science collection / histogram

From: Doug Williams (m.douglas.williams at gmail.com)
Date: Mon Jan 28 18:00:01 EST 2008

Actually, it does bring up an interesting question.  My contract for
histogram-increments says it returns void?.  The above code worked at some
point in the past.  And, adding (void) as the return value for the outer let
makes it work again.  I assume that takes the (exit) call that is bombing
out of the tail position, which was somehow causing the problem. Is that a
correct guess?

If so, does this mean I can't terminate the loop (returning nothing) with a
continuation call?

Just trying to understand the actual problem I have.  I will add the
explicit (void) call to fix it.

Doug

On Mon, Jan 28, 2008 at 3:34 PM, Doug Williams <m.douglas.williams at gmail.com>
wrote:

> 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/6ba1ae00/attachment.html>

Posted on the users mailing list.