jude@discovery.nas.nasa.gov (Jude A. George) (08/21/90)
I recently posted a message asking about the feasability of linking together compiled LISP and C code. Here is a summary of the non-specific responses I received. Thanks again to everyone who replied! Jude ---- Allegro provides a foreign function interface to do exactly what you want. There's a section in the documentation devoted to it. ---- If you are using Franz Allegro, check out the foreign function interface. It is in ch. 10 in my book. Note that this is not portable, of course, but a Franz extension. Calling Lisp functions from C is treated in section 10.8.2, along with examples. I have not used it yet, having just begun with Allegro. Hope this is a useful pointer. ---- In AKCL, you can call both ways. You can get AKCL from rascal.ics.utexas.edu. Don't bother with KCL--it's buggy, slower, and its C interface is inferior. ---- I have done this in both KCL and Allegro (from Franz) Common Lisp. Under KCL, use the defCfun construct to create a C-callable function that is written in somewhat convoluted lisp syntax. Details are in chapter 10 of the KCL Report (part of the distribution). Allegro had a mechanism in which you used 'defun-c-callable and 'register-function to declare a Lisp function as being C-callable and then had your C function call "lisp_call()" with the appropriate arguments. It's been a long time since I used Allegro, so the details are sketchy at best. In both cases, you need to load you compiled C code into the Lisp world. In some ports of KCL, si:faslink doesn't correctly perform incremental loads of C objects and you need to link the compiled C and Lisp functions directly into the KCL core at KCL creation time. I can provide more insight into that KCL problem if you have problems with si:faslink. ---- We originally used Allegro on our project at MIT but switched to KCL for two major reasons: 1. KCL is a LOT smaller. Our dumped KCL executable was about 5.5 megabytes vs. over 8 megs. We were also able to build the dumped KCL with most of the compiled Lisp code in TEXT space rather than DATA space, making it shareable between processes. This is very important when you have over 16 users running this process on a single Sun 3/280. 2. Licensing KCL is very easy - it's also free. It made it easier for us to make our system available to other universities. Having the KCL source code around was also pretty handy. I made a number of mods to deal with incompatibilities with memory allocations done by Ingres, etc. It also let us run major chunks of our software on different platforms without having to buy costly licenses. Just wanted to point out that there are advantages to KCL, but they may not mean a lot to you for your particular application. I'd be happy to provide help if you run into problems using KCL. I've written quite a bit of code that crosses the Lisp/C boundaries using KCL... ---- Here's another alternative that may be just what you're looking for. I haven't tried SIOD myself, but it certainly sounds interesting... >From: gjc@paradigm.com >Newsgroups: comp.lang.lisp >Subject: new version of SIOD (Scheme in one Day) available >References: NIL >Followup-To: NIL >Message-ID: <945@paradigm.com> >SIOD version 2.4 is now available. > >What is SIOD? It is an extremely small scheme implementation in C >arranged as set of subroutines that can be called from any main >program for the purpose of introducing an interpreted extension >language. > >How small is it? Compiling using the VAX/VMS C compiler results in a >total of 16333 bytes of executable code. > >What features? > * Lisp calls C and C calls lisp transparently > * no hassle in C coded functions due to GC or EVAL considerations. > * ability to hook into the read-eval-print loop without modifying the code. > * ability to extend the datatypes without modifying the code. > * mark-and-sweep or stop-and-copy GC selectable at runtime. > * readmacros > * macros > * backquote (quasi-quote) > * optionally loadable pratt (infix-language) parser > >Platforms? > * VAX/VMS * VAX UNIX * SUN-3 * SUN-4 * AMIGA * MACINTOSH * MIPS * CRAY > >Availability? > >Anonymous FTP to BU.EDU (128.197.2.6), cd to users/gjc and get siod-v2.4-shar > >Copyright? Has MIT/X-WINDOWS style copyright notice. Free for any purpose, >including commercial use. ---- :::::::::::::::::::::::::::::::/::::::::::::::::::::::::::::/::::::::::::::: ::::::::Jude:Anand:George:::::%\/:::::jude@nas.nasa.gov::::%\/:::::::::::::: ::::::::endanger:judo:age:::::\/\::::::/\:/\::::::/\:::::::\/\:::::::::::::: :::::::::::::::::::::::::::::::\::::::/ / \/\::/ \:/\::::\:::::::::::::::