home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.scheme
- Path: sparky!uunet!spool.mu.edu!umn.edu!csus.edu!netcom.com!thinman
- From: thinman@netcom.com (Technically Sweet)
- Subject: Scheme & C: a universal interface
- Message-ID: <1993Jan1.202829.11727@netcom.com>
- Organization: International Foundation for Internal Freedom
- Date: Fri, 1 Jan 1993 20:28:29 GMT
- Lines: 55
-
-
- Hi-
-
- I just posted my COOL object library for C to alt.sources.
- It included the interfaces for ELK and SCM. I didn't post
- the S->C one because it's in progress.
-
- The problem with this is that I'm committing the cardinal
- sin of mixing policy with mechanism. Policy is using
- my C object library from Scheme; mechanism is connecting
- Scheme with C.
-
- I've successfully used the exact same C with Scheme->C and
- SCM. This is a reflection on the experience.
-
- Here's how a universal Scheme&C interface should work:
- from C, you register a tuple (string, function pointer,
- argument grammar) with the interface:
-
- int thing1(int);
- int thing2(int, int);
- int thingn(int nargs, int ...);
-
- register("Thing", thing1, 1, INT);
- register("Thing", thing2, 2, INT, INT);
- register("Thing", thingn, NARGS, INT);
-
- Now from Scheme, you can say: -> C mapping
-
- (c-call "Thing" 4) -> thing1(4);
- (c-call "Thing" 5 6) -> thing2(5, 6);
- (c-call "Thing" 7 8 9) -> thingn(3, 7, 8, 9);
-
-
- No Scheme data structures should be exposed to
- the C code, as they are implementation-dependent.
- The hard thing is to map "natural" Scheme calling syntax
- into "natural" C calling syntax. I don't want to write
- twice as much C in a function called from Scheme,
- I want this word done once in the interface.
- It doesn't really matter if the interface is
- a little slower than it could be.
-
- Doubles, vectors, and strings are a pain to translate;
- you have to malloc space and copy them into C space.
- I have no idea how to do lists naturally. The interface
- can enforce static uniform typing of vectors. That is,
- it should have a spec for "vector of chars" and
- copy that through.
-
- --
-
- Lance Norskog
- thinman@netcom.com
- Data is not information is not knowledge is not wisdom.
-