"Embedded Prolog" in C code

Ted Dunning ted at nmsu.edu
Tue May 28 02:00:27 AEST 1991


In article <1991May26.231138.13000 at brolga.cc.uq.oz.au> exnirad at brolga.cc.uq.oz.au (Nirad Sharma) writes:

   Is it possible to write Prolog progams and have them integrated into a c
   program ?

yes, but ... see below.

   BTW,  if anyone can suggest a similar system with, say, Lisp I'd be glad to
   know.

also... same comments



it is generally _MUCH_ easier (as in the supplier supports it) to
embed c code into a running prolog program.  there are number of
reasons for this, chief of which is that the memory models of most
prolog interpreters/runtimes is pretty involved and most programmers
simply can't be trusted to set it all up correctly.

on significant exception to this generalization is quintus prolog
which allows the user bidirectional embedding, c in a prolog program,
or prolog in a c program.  the first is still much easier to make
work.

most commercial lisp implementations allow the former style of
embedding of c code.  if you have source, then you might be reasonably
able to embed the other way.  many publically available scheme (elk,
and scm a prominent examples) interpreters allow full
intercallability.


you should consider the fact that embedding will almost always
seriously compromise debugging of the embedded code.  this is
especially true of embedding c in a more advanced language.  

there are two reasonable outs for this, one is to start the higher
level language from inside a c debugger (this assumes that you have
unstripped executables or .o files) and then after loading your c-code
into prolog (lisp) you break back to the debugger and set up
breakpoints and such.

the other reasonable solution is to implement some form of remote
procedure call which would allow you to debug your prolog program and
your c program with their native debuggers.  an automatic generator of
stubs and argument marshalling code is very helpful with this
approach.

--
	Offer void except where prohibited by law.



More information about the Comp.lang.c mailing list