From: Bob Green
Subject: combining C and LISP
Date: 
Message-ID: <32D46722.1251@ziplink.net>
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.  
Thanks is advance.

From: Martin Cracauer
Subject: Re: combining C and LISP
Date: 
Message-ID: <1997Jan9.085410.22005@wavehh.hanse.de>
Bob Green <······@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
·················@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
--
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
···············@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
From: Will Ware
Subject: Re: combining C and LISP
Date: 
Message-ID: <E3rw4B.CBH@world.std.com>
Martin Cracauer (········@wavehh.hanse.de) wrote:
: With gcl, you have a Tk interface available. This is a very
: lightweigt, easy-to-understand GUI extension.

This is something I'd be interested in, what's the name of it? I
have tried getting CLX running without much success, and this
sounds preferable.
-- 
-------------------------------------------------------------
Will Ware <·····@world.std.com> web <http://world.std.com/~wware/>
PGP fingerprint   45A8 722C D149 10CC   F0CF 48FB 93BF 7289
From: Bob Green
Subject: Re: combining C and LISP
Date: 
Message-ID: <32D5F75C.3D21@ziplink.net>
Martin Cracauer wrote:

> 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.

Indeed.

> 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.

The TCP approach appeals to me as I have had _some_ previous experience 
with 
sockets, and this seems like an elegant way to approach the problem.  I 
will 
have to refamiliarize myself with TCP, but that is something I've wanted 
to 
do anyway.

> Nice thing, this would also work over the Network, the GUI on Windows

This is appealing as well.

> 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.

I appreciate you're response.  I am going to take some time to look up 
and 
digest some of the things you've mentioned.  I'm sure before long I will 
be 
posting again with some question or problem.  

Until then, thank you greatly,

			  Bob
From: Emergent Technologies Inc.
Subject: Re: combining C and LISP
Date: 
Message-ID: <01bc0492$9964fd00$42fc6bcc@default>
I've been doing a little more with ActiveX so I can give you a bit more
precise
answer.

ActiveX is simply a renaming of OLE, and it is built on top of COM
(component
object model).  In addition to being pushed for Internet applications, it
is also
a fundamental component of the Windows 95/NT operating system.  Windows
NT 5.0 will be built on an extended COM model called DCOM (distributed
COM).

ActiveX is just a packaging protocol for structured binary objects; no more
and
no less.  An ActiveX object may implement several ``interfaces'' (I would
call
these ``sets of methods''), but is required to implement the simplest one
called ``IUnknown'' which allows you to maintain a reference count and
query
the object as to what other interfaces may be available.  In theory, the
ActiveX
container could contain anything, but in practice it is usually a Windows
binary
executable.

Many ActiveX objects have methods that allow them to render themselves on
a portion of the screen and methods to reify themselves into printed
representations
of themselves (similar to print-readably and read methods).  So, for
instance, an
HTML page is simply the printed representation of an HTML object, and the
browser
is just a box that tells the HTML object where to render itself.  A real
no-brainer.

ActiveX scripting allows you to associate a script object with a script
engine object.
If a piece of Javascript comes across the internet, the javascript engine
is invoked to
parse the object.  When the page is displayed, certain events are sent to
the
script engine for interpretation.  The script engine is an ActiveX object
that supports
methods that are essentially isomorphic to ``read'', ``eval'', and
``send''.

Since the browser neither knows nor cares how the script engine works, nor
what
the script language is, any language may be used for scripting.  If the
script engine
is not available on the local machine, the browser will fetch it.

While ActiveX is predominantly a browser technology, Microsoft has stated
that
it will be a fundamental part of the OS is the future (and some pre-alpha
code
already exists).  This means that we could use Lisp as a scripting language
for
anything that might support scripting.  For instance, the browser, a
spreadsheet,
a word processor, etc.

I hope this helps.

			~jrm



Cyber Surfer <············@nospam.wildcard.demon.co.uk> wrote in article
<············@wildcard.demon.co.uk>...
> In article <·····················@wavehh.hanse.de>
>            ········@wavehh.hanse.de "Martin Cracauer" writes:
> 
> > Well, do you have library implementations for this protocol for
> > Windows, Mac and Unix, where at least one Unix implementation must be
> > availiable as source (to port to unusual platforms)?
> 
> As I understand it, ActiveX is a part of the MFC framework for
> C++. The reason I'm interested in it, and assume that a few others
> will be too, is that script engines can often be found lurking
> inside apps. ActiveX is a way to make this a little more open,
> by allowing developers to not have to hardcode the language into
> the app. This should allow a few of us to use Lisp as a scripting
> language for Windows apps.
> 
> The current situation doesn't depend on any network protocol.
> -- 
> <URL:http://www.enrapture.com/cybes/> You can never browse enough
>   Martin Rodgers � Developer for Enrapture Limited � London, UK
>        Please remove the "nospam" if you want to email me.
>               "Blow out the candles, HAL." -- Dave
> 
> 
From: Cyber Surfer
Subject: Re: combining C and LISP
Date: 
Message-ID: <853750022snz@wildcard.demon.co.uk>
In article <··························@default>
           ········@eval-apply.com "Emergent Technologies Inc." writes:

> While ActiveX is predominantly a browser technology, Microsoft has stated
> that
> it will be a fundamental part of the OS is the future (and some pre-alpha
> code
> already exists).  This means that we could use Lisp as a scripting language
> for
> anything that might support scripting.  For instance, the browser, a
> spreadsheet,
> a word processor, etc.

That is indeed what I have in mind: decoupling the language from
the app, so that any app may use any language that uses the scripting
technology.

On the other hand, perhaps this will someday be done using the JVM?
That should easily beat ActiveX and JavaScript. Both will have to
compete against ActiveX and VBScript, of course.

Not that this should matter to those of us who'll choose Lisp.
As soon as a Lisp - SCM, for example - can be packaged as a script
engine for ActiveX, we'll be able to use it in our apps. We'll
also be able to use it in _other people's_ apps, which is the
point that I find most interesting.

In a word, leaverage.
 
> I hope this helps.

I think it will! It was a fine explanation.

Many thanks.
-- 
<URL:http://www.enrapture.com/cybes/> You can never browse enough
  Martin Rodgers � Developer for Enrapture Limited � London, UK
       Please remove the "nospam" if you want to email me.
              "Blow out the candles, HAL." -- Dave
From: Chris Bitmead
Subject: Re: combining C and LISP
Date: 
Message-ID: <BITMEADC.97Jan30123144@Alcatel.com.au>
In article <············@wildcard.demon.co.uk> ············@nospam.wildcard.demon.co.uk (Cyber Surfer) writes:

>> 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.

If you're going to let things get this ugly, why not just call
something like eval-string("(main-function para par2"));
From: Cyber Surfer
Subject: Re: combining C and LISP
Date: 
Message-ID: <854615255snz@wildcard.demon.co.uk>
In article <······················@Alcatel.com.au>
           ·············@Alcatel.com.au "Chris Bitmead" writes:

> If you're going to let things get this ugly, why not just call
> something like eval-string("(main-function para par2"));

I don't know about other platforms, but there's a small problem
when using Gambit C for Windows, which is that Windows uses
callback functions, and that won't work with continuations.
Usining sockets (or even pipes) works around this, as the two
threads/processes can then work asychronously.
-- 
<URL:http://www.wildcard.demon.co.uk/> You can never browse enough
  Martin Rodgers | Developer and Information Broker | London, UK
       Please remove the "nospam" if you want to email me.
                  "Blow out the candles, HAL."