chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] sdl.egg v0.2


From: Alex Shinn
Subject: Re: [Chicken-users] sdl.egg v0.2
Date: Wed, 03 Nov 2004 07:00:37 -0600
User-agent: Wanderlust/2.10.1 (Watching The Wheels) SEMI/1.14.6 (Maruoka) FLIM/1.14.6 (Marutamachi) APEL/10.6 Emacs/21.3 (i386-pc-linux-gnu) MULE/5.0 (SAKAKI)

At Wed, 03 Nov 2004 11:47:28 +0000, Tony Garnock-Jones wrote:
> 
> "The reason I am recommending (+) over (bitwise-ior) here is that some
> of the flags do not fit in an immediate small integer, and must be
> represented as inexact numbers. Unfortunately, bitwise-ior only works
> properly when applied to immediate small integers, so there is a
> tradeoff to be made: use (bitwise-ior) where you are *sure* all the
> flags will fit in immediate integers, and use (+) otherwise, bearing
> in mind the fact that (bitwise-ior) gives an answer much more in the
> spirit of a bit set definition: if a flag is already set,
> (bitwise-ior) will not set it twice, where (+) will happily screw up
> the result completely."

Ah, I wasn't thinking about this.  You could of course use the
bit-vectors from iset, but that again breaks away from the simple C
constants.

In this case it may be appropriate to provide flag-add and flag-remove
utilities, something like:

(define (flag-add a b)
  (if (odd? (inexact->exact (/ a b)))
    a
    (+ a b)))

(define (flag-remove a b)
  (if (odd? (inexact->exact (/ a b)))
    (- a b)
    a))

though this doesn't work if b isn't a power of 2, such as
sdl_init_everything.

-- 
Alex




reply via email to

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