From: Matias GUIJARRO
Subject: Lisp & C
Date: 
Message-ID: <39F597AE.F753BF3C@utbm.fr>
I would like to know how to merge Lisp & C in a same program, I mean for
example
writting the interface in C and AI things in Lisp.

How it is possible ? Is there libraries, or something ? Which tools
should I use ?

Thanks for a quick answer.

From: Rainer Joswig
Subject: Re: Lisp & C
Date: 
Message-ID: <joswig-DAE787.16363624102000@news.is-europe.net>
In article <·················@utbm.fr>, Matias GUIJARRO 
<···············@utbm.fr> wrote:

> I would like to know how to merge Lisp & C in a same program, I mean for
> example
> writting the interface in C and AI things in Lisp.
> 
> How it is possible ? Is there libraries, or something ? Which tools
> should I use ?
> 
> Thanks for a quick answer.

See http://www.lisp.org/ for information about the various
Lisp systems. Some Lisps are (mostly) written in C or
compile to C. There are special purpose libraries designed
to be embedded into C-based software. See also
the various Scheme (a Lisp dialect) systems.

Most Lisp systems can interface to external routines
(which might be written in C or Fortran or ...).
So a Lisp program can call external routines. Some
Lisps also allow callbacks into Lisp (for example to allow
an OS to call arbitrary Lisp code).

Finally several Lisp systems have extensive libraries for
programming graphical user interfaces.

-- 
Rainer Joswig, Hamburg, Germany
Email: ·············@corporate-world.lisp.de
Web: http://corporate-world.lisp.de/
From: Daniel Kiracofe
Subject: Re: Lisp & C
Date: 
Message-ID: <39FA032A.168B6967@osu.edu>
> > I would like to know how to merge Lisp & C in a same program, I mean for
> > example
> > writting the interface in C and AI things in Lisp.
> >
> > How it is possible ? Is there libraries, or something ? Which tools
> > should I use ?
> >
> > Thanks for a quick answer.
> 
> See http://www.lisp.org/ for information about the various
> Lisp systems. Some Lisps are (mostly) written in C or
> compile to C. There are special purpose libraries designed
> to be embedded into C-based software. See also
> the various Scheme (a Lisp dialect) systems.
> 
> Most Lisp systems can interface to external routines
> (which might be written in C or Fortran or ...).
> So a Lisp program can call external routines. Some
> Lisps also allow callbacks into Lisp (for example to allow
> an OS to call arbitrary Lisp code).
> 
> Finally several Lisp systems have extensive libraries for
> programming graphical user interfaces.

 I have a related question.  I've figured out how to get Lisp/Scheme to
interface to my C code, but my problem is that my C code is
multi-threaded.  Everything I found so far generally tends to allocate
some global interpreter state, so it's not reentrant.  So, what I need
is a Lisp/Scheme implementation that I can call from C, that is
reentrant.  Any suggestions? TIA...

-- 
/* Daniel */
E-mail: ···@unxsoft.com
Personal Homepage: http://www.cis.ohio-state.edu/~kiracofe

"Fear is only afraid of the absence of itself" - Mediocrates
From: Erik Naggum
Subject: Re: Lisp & C
Date: 
Message-ID: <3181714929335190@naggum.net>
* Daniel Kiracofe <··········@osu.edu>
| I've figured out how to get Lisp/Scheme to interface to my C code,
| but my problem is that my C code is multi-threaded.  Everything I
| found so far generally tends to allocate some global interpreter
| state, so it's not reentrant.  So, what I need is a Lisp/Scheme
| implementation that I can call from C, that is reentrant.  Any
| suggestions? TIA...

  Interprocess communication including shared memory and semaphores.
  I have started on a general package for this several times, but
  always end up specializing it into oblivion as far as generality and
  publishability is concerned.  I really do _not_ want C code that I
  don't trust to muck around in the Lisp memory.  I also tend to
  design my own protocols over sockets to make the coupling as loose
  as possible.  (The more common protocols use far too tight coupling
  for me qua protocols, and not at all tight enough if they pretend to
  be shared memory across the wire.)

#:Erik
-- 
  Does anyone remember where I parked Air Force One?
                                   -- George W. Bush
From: Eugene Zaikonnikov
Subject: Re: Lisp & C
Date: 
Message-ID: <6y66mithwb.fsf@localhost.localdomain>
Hi Matias,

* "Matias" == Matias GUIJARRO <···············@utbm.fr> writes:

Matias>  I would like to know how to merge Lisp & C in a same program,
Matias>  I mean for example writting the interface in C and AI things
Matias>  in Lisp.

What you need is Foreign Functions Interface (FFI for short). It is
not in ANSI standard, but many implementations (CMU, LispWorks, ACL,
MCL to name a few) carry their own (non-portable) versions. Take a
look at documentation bundled with your compiler.

Alternatively, you may use CL compiler which is able to translate to
C, and then link it to the rest of your project.

CormanLisp also provides COM interface to lisp code; ACL Enterprise 5
is able to produce DLLs.

Another option could be not to hard-link Lisp and C code, but to make
them communicate somehow (e.g. through sockets).

-- 
  Eugene
From: Erik Naggum
Subject: Re: Lisp & C
Date: 
Message-ID: <3181389901300909@naggum.net>
* Matias GUIJARRO <···············@utbm.fr>
| I would like to know how to merge Lisp & C in a same program, I mean
| for example writting the interface in C and AI things in Lisp.

  If you seperate the functionality that well, you might benefit from
  not marrying (merging) the two together, but rather to use a looser
  coupling through an intermediate layer.  Several options exists for
  this, including CORBA, RPC, and rolling your own protocol, using
  socket communication.  You may find this easier on your design than
  to do extensive amounts of work in C-land while running a Lisp
  system, mostly because calls to C are usually assumed to be short
  special service calls.  If you are dealing with a more server-like
  approach to the AI stuff while the C subsystem is doing the (user)
  interface, you will probably benefit from a very loose coupling.

  Unfortunately, protocol design and implementation in C is much
  harder than in Lisp, so C programmers do not naturally gravitate
  towards those kinds of designs, but prefer expensive solutions as
  long as they are in some sort of library.

#:Erik
-- 
  I agree with everything you say, but I would
  attack to death your right to say it.
				-- Tom Stoppard