guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to stay in fixnum range?


From: Neil Jerram
Subject: Re: How to stay in fixnum range?
Date: Wed, 21 Jan 2009 17:52:19 +0000

2009/1/21 Panicz Maciej Godek <address@hidden>:
>
> I expect that, after reaching the maximum count (the range of int), the timer
> twists back to zero, instead of growing boundlessly.
>
> In that case, the following code may fail:
>
> (define (for-ticks-pass-time-left ticks operation)
>  (let ((total-ticks (+ ticks (get-internal-real-time)))
>        (elapsed-ticks 0)
>        (current-ticks 0)
>        (processed-ticks 0))
>    (while #t
>      (set! current-ticks (get-internal-real-time))
>      (set! elapsed-ticks (+ elapsed-ticks (- current-ticks processed-ticks)))
>      (set! processed-ticks current-ticks)
>      (if (>= elapsed-ticks total-ticks)
>        (break))
>      (operation (- total-ticks elapsed-ticks)))
>    (- elapsed-ticks total-ticks)))

Thanks for explaining.  In terms of the libguile Scheme API, it seems
to me that there isn't currently a good answer to this.  Either we
should implement (get-internal-real-time) such that it doesn't wrap -
which it doesn't look like we do currently - or we should provide
another primitive to indicate what the maximum (and hence wrapping)
value is.

(It may in practice be most-positive-fixnum, but Scheme code shouldn't
have to assume that.)

If you're getting into C code anyway, would you be interested in
writing a libguile patch for this?

Regards,
        Neil




reply via email to

[Prev in Thread] Current Thread [Next in Thread]