[plt-scheme] _bitmask usage in foreign.ss

From: Eli Barzilay (eli at barzilay.org)
Date: Mon Sep 12 08:50:09 EDT 2005

On Sep 11, Jon Rafkind wrote:
> This pertains to the foreign function interface( foreign.ss ) in 
> mzscheme. Given the following C code
> #define a 1
> #define b 2
> #define c 4
> #define d 8
> #define foo (a|c)
> What is the equivalent with the _bitmask syntax? Could something like
> (_bitmask '(a 1
>                     b 2
>                     c 4
>                     d 8
>                     foo (a|c)))
> be supported in the future?

No, you'd use

  (_bitmask '(a = 1
              d = 8))

then you can pass '(a c) as a value that will be translated to 5, or
you can define foo as a new symbol for that:

  (_bitmask '(a = 1
              d = 8
              foo = ,(bitwise-ior 1 4)))

but this means that if it is used as a result value, and that value is
5, the translation to Scheme will give you '(a c foo), since 5
contains all of them.

> Also, Eli, could you add an example usage of _enum and _bitmask on
> the documentation on the website? I keep having to remind myself how
> to use them.

Ugh...  So why not write a short example with some nice text and mail

          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!

Posted on the users mailing list.