From: Zachary Turner
Subject: linking lisp to C/C++
Date: 
Message-ID: <73c99f$nl6$1@uuneo.neosoft.com>
can LISP functions be linked to C/C++?

From: David Thornley
Subject: Re: linking lisp to C/C++
Date: 
Message-ID: <k1C62.559$764.2378674@ptah.visi.com>
In article <············@uuneo.neosoft.com>,
Zachary Turner <·······@elsitech.com> wrote:
>can LISP functions be linked to C/C++?
>
Um, what platform are we talking about?  What Lisp implementation?
What C or C++ implementation?

On my Macintosh, with Macintosh Common Lisp and Metrowerks Codewarrior,
it's easy (provided you do not care about supporting old Macs.).
You simply compile the C and C++ as a shared library, provide a
pointer to the library, define a few entry points in Lisp, and
you're off.  It is necessary that the main program be in Lisp
and the C or C++ in a shared library.



--
David H. Thornley                        | These opinions are mine.  I
·····@thornley.net                       | do give them freely to those
http://www.thornley.net/~thornley/david/ | who run too slowly.       O-
From: Zachary Turner
Subject: Re: linking lisp to C/C++
Date: 
Message-ID: <73eur9$ff6$1@uuneo.neosoft.com>
>Um, what platform are we talking about?  What Lisp implementation?
>What C or C++ implementation?
>
>On my Macintosh, with Macintosh Common Lisp and Metrowerks Codewarrior,
>it's easy (provided you do not care about supporting old Macs.).
>You simply compile the C and C++ as a shared library, provide a
>pointer to the library, define a few entry points in Lisp, and
>you're off.  It is necessary that the main program be in Lisp
>and the C or C++ in a shared library.


No No.  l  I want the other way around.  I want to know if I can write code
in LISP and link it into a program i've written in C or C++.  It shouldn't
matter what platform or implementation of anything I'm on, unless there are
only certain LISP compilers that can do this.  C functions have a standard
calling convention.  It's a matter of whether or not the LISP compiler can
compile it to a C function.  All it really has to do is put the underscore
in front of a function name (of course i know nothing about LISP or how it
handles functions.  the whole reason i started the thread is because i want
to know what i can and can't do with LISP, seeing as how i'm about to start
getting heavily into AI programming.)  But just to clarify i'm using Windows
NT 4.0 and Visual Studio 6.0.  So i want to write some functions in LISP,
compile them into a .DLL (using Allegro CL 5.0 more than likely) and call
one of these .DLL functions from my C++ program.  Can this be done?
From: Christopher Browne
Subject: Re: linking lisp to C/C++
Date: 
Message-ID: <73fnft$ll3$6@blue.hex.net>
On Tue, 24 Nov 1998 12:45:12 -0000, Zachary Turner <·······@elsitech.com> wrote:
>>Um, what platform are we talking about?  What Lisp implementation?
>>What C or C++ implementation?
>>
>>On my Macintosh, with Macintosh Common Lisp and Metrowerks Codewarrior,
>>it's easy (provided you do not care about supporting old Macs.).
>>You simply compile the C and C++ as a shared library, provide a
>>pointer to the library, define a few entry points in Lisp, and
>>you're off.  It is necessary that the main program be in Lisp
>>and the C or C++ in a shared library.
>
>No No.  l  I want the other way around.  I want to know if I can write code
>in LISP and link it into a program i've written in C or C++.  It shouldn't
>matter what platform or implementation of anything I'm on, unless there are
>only certain LISP compilers that can do this.  C functions have a standard
>calling convention.  It's a matter of whether or not the LISP compiler can
>compile it to a C function.  All it really has to do is put the underscore
>in front of a function name (of course i know nothing about LISP or how it
>handles functions.  the whole reason i started the thread is because i want
>to know what i can and can't do with LISP, seeing as how i'm about to start
>getting heavily into AI programming.)  But just to clarify i'm using Windows
>NT 4.0 and Visual Studio 6.0.  So i want to write some functions in LISP,
>compile them into a .DLL (using Allegro CL 5.0 more than likely) and call
>one of these .DLL functions from my C++ program.  Can this be done?

Definitely somewhat more problematic, as Lisp programs have some
"expectations" as to their access to memory, and management thereof,
particularly in the context of garbage-collectible objects. 

For some insight, you might look at the model used by Guile, a SCM
variant, for how it may be embedded into C applications, you might want
to take a look at:

http://nis-www.lanl.gov/~rosalia/gnudl-doc/learn_libguile_toc.html
http://www.cygnus.com/library/ctr/guile.html
http://www.gnu.org/software/guile/guile.html

The basic point of the exercise is that any variables that you want to
pull into the C/C++ side from the "Lisp side of the world" have to be
specially accessed; variables that you want to push from the "C/C++
side" to the "Lisp side" must similarly be carefully defined so that
garbage collection sees them in an appropriate light. 

-- 
[In response to deprecations of the use of <linux/*.h>]  ...I prefer code 
that only compiles on Linux... I really don't care to help other
operating systems grow.  -- Albert D. Cahalan <········@saturn.cs.uml.edu> 
········@hex.net- <http://www.hex.net/~cbbrowne/lsf.html>
From: Bruce Tobin
Subject: Re: linking lisp to C/C++
Date: 
Message-ID: <36698AA6.2964C455@columbus.rr.com>
Zachary Turner wrote:

> [..] But just to clarify i'm using Windows
> NT 4.0 and Visual Studio 6.0.  So i want to write some functions in LISP,
> compile them into a .DLL (using Allegro CL 5.0 more than likely) and call
> one of these .DLL functions from my C++ program.  Can this be done?

Yes.  ACL 5 can compile into DLL format.  ACL 5 has just about everything that a
lot of folks in this newsgroup have been clamoring for; I strongly recommend
that anyone who's thinking about doing Windows development give it a look.
From: Steve Jacobson
Subject: Re: linking lisp to C/C++
Date: 
Message-ID: <73eqvi$4mi$1@news.franz.com>
Zachary Turner wrote in message <············@uuneo.neosoft.com>...
>can LISP functions be linked to C/C++?
>
>

You can do it with Allegro Common Lisp 5.0
From: Howard R. Stearns
Subject: Re: linking lisp to C/C++
Date: 
Message-ID: <365AF660.FF18429B@elwood.com>
Zachary Turner wrote:
> 
> can LISP functions be linked to C/C++?

See http://www.elwood.com/eclipse-info, and in particular, the paper
link near the top.

More generally, see http://www.elwood.com/alu/table/combine.htm
From: willi
Subject: Re: linking lisp to C/C++
Date: 
Message-ID: <73ecu0$sib$1@nets3.rz.RWTH-Aachen.DE>
NO, you can only link c++ funktions to lisp not  vice versa

So long willi

Zachary Turner schrieb in Nachricht <············@uuneo.neosoft.com>...
>can LISP functions be linked to C/C++?
>
>
From: Marco Antoniotti
Subject: Re: linking lisp to C/C++
Date: 
Message-ID: <lwyap15am1.fsf@copernico.parades.rm.cnr.it>
"willi" <·····@willi.com> writes:

> NO, you can only link c++ funktions to lisp not  vice versa
> 

AFAIK not even that.  I think most languages support linking of C
objects, not C++. The only way to link in the C++ is to go through a C
layer, pretty much the way it is done in JNI.

Cheers

-- 
Marco Antoniotti ===========================================
PARADES, Via San Pantaleo 66, I-00186 Rome, ITALY
tel. +39 - (0)6 - 68 10 03 17, fax. +39 - (0)6 - 68 80 79 26
http://www.parades.rm.cnr.it
From: Pierre Mai
Subject: Re: linking lisp to C/C++
Date: 
Message-ID: <873e79jhqm.fsf@dent.isdn.cs.tu-berlin.de>
"willi" <·····@willi.com> writes:

> NO, you can only link c++ funktions to lisp not  vice versa
> 
> So long willi
> 
> Zachary Turner schrieb in Nachricht <············@uuneo.neosoft.com>...
> >can LISP functions be linked to C/C++?

There is at least one implementation, where this is wrong: Eclipse
Common Lisp compiles Common Lisp functions to C functions, which can be
linked against other C/C++ code.  Eclipse is a very reasonably priced
commercial CL implementation available for Win32 and Linux, IIRC.  Take
a look at http://www.elwood.com/eclipse/ for more information.

IIRC there is also EcoLisp, which does similar things, but I don't
know any details...

Regs, Pierre.

-- 
Pierre Mai <····@acm.org>               http://home.pages.de/~trillian/
  "One smaller motivation which, in part, stems from altruism is Microsoft-
   bashing." [Microsoft memo, see http://www.opensource.org/halloween1.html]