[plt-scheme] Re: image manipulation

From: John Kozak (jk at xylema.org)
Date: Thu Mar 25 16:50:54 EST 2004

 [...]
 > > Oh, absolutely.  There are advantages to SWIG, though: presumably,
 > > as it's the de facto standard, there'll be a (growing) library of
 > > bindings to all sorts of nice and useful stuff.  Perhaps an
 > > interpretative back-end should be added to SWIG?
 > 
 > But if you have a dynamic thing working, you don't need any library...
 > It's all there -- all you need is the Scheme declarations that match
 > the C headers.

Yes, but they're non-trivial to do nicely, because the standard
representations for common abstractions are quite different in C and
scheme.   For example, something like this in C:

  #define TASTE_SWEET	0x0001
  #define TASTE_SOUR	0x0002
  #define TASTE_SALT	0x0004
  #define TASTE_BITTER	0x0008
  #define TASTE_UMAMI	0x0010

  int nibble_snack(char *name,int taste);

  taste("chowmein",TASTE_SWEET|TASTE_SOUR);

would be nicely mapped to scheme as something like:

  (taste 'chowmein '(sweet sour))

You can use heuristics to spot things like C's pseudo-enum pattern
(the SCM/w FFI did, AFAICR), but that gets complicated, too (often
a single word is split into multiple regions under and-masks). Also, 
subtleties in the semantics of structs; unions...

Essentially, it's a process that's, I believe, always going to be at
least partly manual, and sometimes quite a slog (try LAPACK!), even
with a tool like SWIG - so it's nice to be able to share with other
groups whose concerns are similar (I suspect many dynamic languages
would prefer to do the above scheme-style rather than C-style).

John




Posted on the users mailing list.