Newsgroups: comp.lang.lisp
Path: cantaloupe.srv.cs.cmu.edu!rochester!cornellcs!newsstand.cit.cornell.edu!news.acsu.buffalo.edu!news.uoregon.edu!tezcat!news.bbnplanet.com!cam-news-hub1.bbnplanet.com!news.mathworks.com!fu-berlin.de!news-ber1.dfn.de!news-ham1.dfn.de!news.dkrz.de!news.uni-hamburg.de!news.Hanse.DE!wavehh.hanse.de!cracauer
From: cracauer@wavehh.hanse.de (Martin Cracauer)
Subject: Re: combining C and LISP
Message-ID: <1997Jan9.085410.22005@wavehh.hanse.de>
Reply-To: cracauer@wavehh.hanse.de
Organization: '(a (cons structive organization))
References: <32D46722.1251@ziplink.net>
Date: Thu, 9 Jan 97 08:54:10 GMT
Lines: 55

Bob Green <rgreen@ziplink.net> writes:

>I want to program a user interface in C++ for a genetic programming 
>system I've make in LISP.  Right now I don't have the slightly idea how 
>to proceed.  Can anyone give me any advice or point me to some reference 
>material (preferably on the web) to get me started on this.  I have a DOS 
>based system with Turbo C++ and Freelisp, and I have a Linux system with 
>GNU C and GNU common lisp.  I can use either of these combinations.  The 
>prospect of doing the user interface in lisp frightens me, as I'd rather 
>use LISP for the elegant stuff and C for the messy real world stuff.  

The FFI's of CL implementation vary very much. I don't know anything
about FreeLisp, so I'll have to comment on the Unix part.

With gcl, you have a Tk interface available. This is a very
lightweigt, easy-to-understand GUI extension. You don't even have to
master Lisp to use it, knowledge of Tk (yes, the only normally used
with Tcl) and basic Lisp is sufficient. There are readable textbooks
for Tk/Tcl and most applies when using Tk from another language.

I'm quite sure the Tk interface is right for your needs, although I
didn't use it by myself.

If you are up to use a C GUI library, you best start by looking into
existing bindings like CLX/CLUE/CLIO, CLM and the CMUCL Motif stuff
(See the Lisp FAQ for places to get them). I'm sure you will not try
to reimplement such a monster. If you are, please meet our
free-clim-request@cons.org mailing list :-)

More seriously, I'm sure you underestimate how much interaction
bewteen Lisp and C is needed. You will for sure need GUI callbacks
into Lisp code and at that point things become ugly.

Another solution is not to couple C and Lisp in the same program, but
to develop a little protocol and let Lisp and C communicate via TCP
sockets. That way, you can do a GUI in pure C and call Lisp to
evaluate code. Lisp's reader capabilities make this very easy, you
could do this in C: `write("(main-function para par2)",n,socket)` and
you would get Lisp's answer on the socket.

Nice thing, this would also work over the Network, the GUI on Windows
and calling gcl on Unix (I don't know whether Freelisp has TCP sockets
at all). I don't know much about gcl's sockets interface, look into
./o/sockets.c, ./o/sockets.ini, ./gcl-tk/tkl.lisp to get started.

If you'd use CMUCL, I could help you a bit. It's (serve-event )
function would be quite useful. And it has a chapter in the manual
about it's TCP sockets interface.

Martin
--
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Martin_Cracauer@wavehh.hanse.de http://cracauer.cons.org  Fax.: +4940 5228536
"As far as I'm concerned,  if something is so complicated that you can't ex-
 plain it in 10 seconds, then it's probably not worth knowing anyway"- Calvin
