home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / scheme / 2857 < prev    next >
Encoding:
Text File  |  1993-01-04  |  1.8 KB  |  57 lines

  1. Newsgroups: comp.lang.scheme
  2. Path: sparky!uunet!wupost!sdd.hp.com!swrinde!gatech!usenet.ins.cwru.edu!agate!spool.mu.edu!sgiblab!smsc.sony.com!sonyusa!sinyaw
  3. From: sinyaw@starbright.smsc.sony.com (Sin-Yaw Wang)
  4. Subject: Re: Scheme & C: a universal interface
  5. In-Reply-To: thinman@netcom.com's message of Fri, 1 Jan 1993 20:28:29 GMT
  6. Message-ID: <SINYAW.93Jan4153040@starbright.smsc.sony.com>
  7. Sender: news@smsc.sony.com (Usenet News System)
  8. Organization: Sony Microsystems
  9. References: <1993Jan1.202829.11727@netcom.com>
  10. Date: 4 Jan 93 15:30:40
  11. Lines: 44
  12.  
  13. In article <1993Jan1.202829.11727@netcom.com> thinman@netcom.com (Technically Sweet) writes:
  14.  
  15.    Here's how a universal Scheme&C interface should work:
  16.    from C, you register a tuple (string, function pointer,
  17.    argument grammar) with the interface:
  18.  
  19.        int thing1(int);
  20.        int thing2(int, int);
  21.        int thingn(int nargs, int ...);
  22.  
  23.        register("Thing", thing1, 1, INT);
  24.        register("Thing", thing2, 2, INT, INT);
  25.        register("Thing", thingn, NARGS, INT);
  26.  
  27.    Now from Scheme, you can say:    -> C mapping
  28.  
  29.        (c-call "Thing" 4)    -> thing1(4);
  30.        (c-call "Thing" 5 6)    -> thing2(5, 6);
  31.        (c-call "Thing" 7 8 9)    -> thingn(3, 7, 8, 9);
  32.  
  33.  
  34.  
  35.  
  36. Since you require C program to register, "Thing" is put into Scheme's name
  37. space already.  Why not simply call these C functions directly?  Like:
  38.  
  39.     (Thing 4) -> thing1(4)
  40.     (Thing 5 6) -> thing2(5, 6)
  41.     
  42. This way, the calling syntax is transparent.
  43.  
  44.  
  45. I would also like to propose the removal of "not to expose Scheme object to
  46. C" rule.  Instead, there should be a library of C routines to parse Scheme
  47. objects (like pair, vector, etc.).  You can specify a native Scheme object
  48. by registering like this:
  49.  
  50.     register("Thing", "thing_scm", 1, SCM_OBJECT);
  51.  
  52.     
  53. Lastly, "register" is a lousy choice of name.
  54.  
  55. --
  56. Sin-Yaw Wang, sinyaw@smsc.sony.com, 408-944-4076
  57.