🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.lisp.x
Article #34

Re: exploratory system for unix system calls/facilities

#34
From: Eric Raible
Date: Fri, 20 Oct 1989 21:18
63 lines
2300 bytes
In article <1852@xyzzy.UUCP> kan@mutley.dg.com () writes:
>I've been looking for the issue for weeks, but finally found it today.
>It's in the Byte IBM Special Edition for Fall 1988 (volume 13, #11).
>To summarize, C library functions are called with the c-call function.
>C style structures are handled like this:
>
>/* from their example */
>struct FileFindBuf {
>	unsigned create_date;
>	unsigned create_time;
>	unsigned access_date;
>.
>}
>
>becomes:
>
>(define FileFindBuf
>	'((word create_date)
>	  (word create_time)
>	  (word access_date)
>.
>))
>
>Unfortunately, the source for the extentions of XLISP to OS2XLISP were not
>published in the issue.  I assume it's available from the usual Byte
>source sources.
>

I needed to access and set C structures (i.e. defined and allocated by C),
so I hacked together a parser that converts C structure definitions into
a form that is suitable for use in scheme, and some scheme utility code
to use it.

As an example, given:

typedef struct {
   int i;
   char c;
   float f;
} Example;

And a scheme function 'get-an-example' that returns a pointer to a new
example, I can do the following:

(make-struct-accessor 'Example 'i)
(make-struct-accessor 'Example 'c)
(make-struct-accessor 'Example 'f)

(define s (get-an-example))

(set-example-i! s 10)
(set-example-c! s #\newline)
(set-example-f! s 1.2)

(+ (example-i s) (example-f s)) => 11.2

Note that this code is not really suitable for structures in scheme
(although it could be adapted), but rather for accessing and modifying
structures in C from scheme.

Mail to me for more info.

- Eric (raible@orville.nas.nasa.gov)
Technical Details
Message-ID: <3515@amelia.nas.nasa.gov>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!uakari.primate.wisc.edu!gem.mps.ohio-state.edu!swrinde!ucsd!ames!amelia!orville.nas.nasa.gov!raible
References: <1753@xyzzy.UUCP> <4139@hplabsz.HPL.HP.COM> <1852@xyzzy.UUCP>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!uakari.primate.wisc.edu!gem.mps.ohio-state.edu!swrinde!ucsd!ames!amelia!orville.nas.nasa.gov!raible
From: raible@orville.nas.nasa.gov (Eric Raible)
Newsgroups: comp.lang.lisp.x
Subject: Re: exploratory system for unix system calls/facilities
Message-ID: <3515@amelia.nas.nasa.gov>
Date: 20 Oct 89 21:18:19 GMT
References: <1753@xyzzy.UUCP> <4139@hplabsz.HPL.HP.COM> <1852@xyzzy.UUCP>
Sender: news@amelia.nas.nasa.gov
Reply-To: raible@orville.nas.nasa.gov (Eric Raible)
Organization: NASA Ames Research Center, Moffett Field, CA
Lines: 63