home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / scheme / 2850 < prev    next >
Encoding:
Text File  |  1993-01-01  |  2.0 KB  |  65 lines

  1. Newsgroups: comp.lang.scheme
  2. Path: sparky!uunet!spool.mu.edu!umn.edu!csus.edu!netcom.com!thinman
  3. From: thinman@netcom.com (Technically Sweet)
  4. Subject: Scheme & C: a universal interface
  5. Message-ID: <1993Jan1.202829.11727@netcom.com>
  6. Organization: International Foundation for Internal Freedom
  7. Date: Fri, 1 Jan 1993 20:28:29 GMT
  8. Lines: 55
  9.  
  10.  
  11. Hi-
  12.  
  13. I just posted my COOL object library for C to alt.sources.
  14. It included the interfaces for ELK and SCM.  I didn't post
  15. the S->C one because it's in progress.
  16.  
  17. The problem with this is that I'm committing the cardinal
  18. sin of mixing policy with mechanism.  Policy is using
  19. my C object library from Scheme; mechanism is connecting
  20. Scheme with C.
  21.  
  22. I've successfully used the exact same C with Scheme->C and 
  23. SCM.  This is a reflection on the experience.
  24.  
  25. Here's how a universal Scheme&C interface should work:
  26. from C, you register a tuple (string, function pointer,
  27. argument grammar) with the interface:
  28.  
  29.     int thing1(int);
  30.     int thing2(int, int);
  31.     int thingn(int nargs, int ...);
  32.  
  33.         register("Thing", thing1, 1, INT);
  34.         register("Thing", thing2, 2, INT, INT);
  35.         register("Thing", thingn, NARGS, INT);
  36.  
  37. Now from Scheme, you can say:    -> C mapping
  38.     
  39.     (c-call "Thing" 4)    -> thing1(4);
  40.     (c-call "Thing" 5 6)    -> thing2(5, 6);
  41.     (c-call "Thing" 7 8 9)    -> thingn(3, 7, 8, 9);
  42.         
  43.  
  44. No Scheme data structures should be exposed to
  45. the C code, as they are implementation-dependent.
  46. The hard thing is to map "natural" Scheme calling syntax
  47. into "natural" C calling syntax.  I don't want to write
  48. twice as much C in a function called from Scheme,
  49. I want this word done once in the interface.
  50. It doesn't really matter if the interface is
  51. a little slower than it could be.  
  52.  
  53. Doubles, vectors, and strings are a pain to translate;
  54. you have to malloc space and copy them into C space.
  55. I have no idea how to do lists naturally.  The interface
  56. can enforce static uniform typing of vectors.  That is,
  57. it should have a spec for "vector of chars" and
  58. copy that through.
  59.  
  60. -- 
  61.  
  62. Lance Norskog
  63. thinman@netcom.com
  64. Data is not information is not knowledge is not wisdom.
  65.