From: Laila C. Khreisat
Subject: Calling a Lisp function from a C program Urgent
Date: 
Message-ID: <199704281736.NAA15372@dynamo.cs.columbia.edu>
I need to call a Lisp function from a C program.
Is there a way to call the Lisp function with its arguments
supplied, without having to run the Lisp interpreter interactively?

From: Heiko Kirschke
Subject: Re: Calling a Lisp function from a C program Urgent
Date: 
Message-ID: <u9122nx33.fsf@poet.de>
·····@news.cs.columbia.edu ("Laila C. Khreisat") writes:

> I need to call a Lisp function from a C program.
> Is there a way to call the Lisp function with its arguments
> supplied, without having to run the Lisp interpreter interactively?

*Shocking*! C calling LISP! Most people in the LISP community would
expect it to be the other way round, i.e. LISP calling C for doing any
lower tasks ...

To answer your question, you have to be more specific: \emph{Which}
LISP should be called? Allegro, LispWorks, MCL, ... In any case,
you'll run into problems when you expect to call a LISP function from
C. The LISP systems I know up to now must be started up first before
they will delegate processor control to a C function. Looks to me as
if non of the LISP systems was desgined for being a subsystem to
another system. Arrogance? (My ;-) Ignorance?

If you just want to call a `small' LISP function from C, the best
advice I can give is to rewrite the function in C. If you want to call
a whole LISP system with many functions, you can perhaps manage that
by using a stream between the C and LISP process, but this will
involve much overhead to the communication. The idea is to connect
from C to the LISP process using stdout and stdin, i.e. C would
startup LISP by a call to popen(), send input to it by pwrite() and
read output from it by pread(); this implies that all data is passed
foth and back as strings, which must be converted into the
representation you need (no problem for LISP, bigger problem for C).

Viele Gruesse, Heiko
--
Heiko Kirschke             EMail: ··············@poet.de
POET Software GmbH         Web:   http://www.poet.de/
Fossredder 12              Tel:   +49 40 60990-263
D-22359 Hamburg            Fax:   +49 40 60990-115
From: Neil Cohen
Subject: Re: Calling a Lisp function from a C program Urgent
Date: 
Message-ID: <ncohen-0105971017110001@net-6-159.austin.eden.com>
In article <·············@poet.de>, Heiko Kirschke
<··············@poet.de> wrote:

> ·····@news.cs.columbia.edu ("Laila C. Khreisat") writes:
> 
> > I need to call a Lisp function from a C program.
> > Is there a way to call the Lisp function with its arguments
> > supplied, without having to run the Lisp interpreter interactively?
> 
> *Shocking*! C calling LISP! Most people in the LISP community would
> expect it to be the other way round, i.e. LISP calling C for doing any
> lower tasks ...

   Doesn't seem to be so strange.  I'm writing a Lisp program and the
user-interface will be written in C.  While it's possible to have a top
level lisp function call the interface function for each piece of input,
it's far simpler for it to call the Lisp function when the calculations
are needed.

    neil
Neil Cohen
Please remove the .nl before replying.
From: Roberta Valent
Subject: Re: Calling a Lisp function from a C program Urgent
Date: 
Message-ID: <336986A3.94D@ix.netcom.com>
Neil Cohen wrote:
> 
> In article <·············@poet.de>, Heiko Kirschke
> <··············@poet.de> wrote:
> 
> > ·····@news.cs.columbia.edu ("Laila C. Khreisat") writes:
> >
> > > I need to call a Lisp function from a C program.
> > > Is there a way to call the Lisp function with its arguments
> > > supplied, without having to run the Lisp interpreter interactively?
> >
> > *Shocking*! C calling LISP! Most people in the LISP community would
> > expect it to be the other way round, i.e. LISP calling C for doing any
> > lower tasks ...

Not that shocking !

>    Doesn't seem to be so strange.  I'm writing a Lisp program and the
> user-interface will be written in C.  While it's possible to have a top
> level lisp function call the interface function for each piece of input,
> it's far simpler for it to call the Lisp function when the calculations
> are needed.

Well, it does depend from the Lisp compiler that you do use.
In Allegro, for instance there is a .h file provided with Allegro,
that contains the C types necessary to parse or build Lisp Objects.

Since in Lisp, values are typed, in all the cases you are not passing
from C a simple value, but a pointer to a Lisp objects, "storing" the
type of the value and the value itself.

In other Lisp implementations, and depending on which foreign-function
interface they do have, things could be different.

>     neil
> Neil Cohen
> Please remove the .nl before replying.