[comp.lang.c] "Embedded Prolog" in C code

exnirad@brolga.cc.uq.oz.au (Nirad Sharma) (05/27/91)

Is it possible to write Prolog progams and have them integrated into a c
program ?  I seem to remember that Turbo Prolog on the PC platform allows
this.  I am looking for a Unix (SYSV) solution which would allow prolog
units to be written and either compiled and linked to the c code or be
interpreted at run-time.  Some extensive logic needs to be built into some
algorithms that I am using for a database application. While I have already
coded some of this logic in c I would prefer to convert the existing and
the future code to prolog for ease of programming and verification.

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

Thanks for any help / pointers.

-- 
Nirad Sharma  (exnirad@brolga.cc.uq.oz.au)		Phone : (+61 7) 365 7575
Systems Programmer					Fax :	(+61 7) 870 5080
Continuing Education Unit
The University of Queensland.  QLD  4072

fore057@csc.canterbury.ac.nz (05/27/91)

In article <1991May26.231138.13000@brolga.cc.uq.oz.au>, exnirad@brolga.cc.uq.oz.au (Nirad Sharma) writes:
> Is it possible to write Prolog progams and have them integrated into a c
> program ?  I seem to remember that Turbo Prolog on the PC platform allows
> this.  I am looking for a Unix (SYSV) solution which would allow prolog
> units to be written and either compiled and linked to the c code or be
> interpreted at run-time.  Some extensive logic needs to be built into some
> algorithms that I am using for a database application. While I have already
> coded some of this logic in c I would prefer to convert the existing and
> the future code to prolog for ease of programming and verification.

Turbo Prolog is now marketed by the original developers, and is called PDC
Prolog.  There is a UNIX version.  I suggest you ask if it will do what you
want.  The address is:

Prolog Development Center ApS.
H.J. Holst Vej 5A
DK-2605 Broendby
Copenhagen, Denmark

They used to have a USENET address, but my Email hasn't been reaching them
recently.

own@castle.ed.ac.uk (O Morgan) (05/27/91)

>In article <1991May26.231138.13000@brolga.cc.uq.oz.au>, exnirad@brolga.cc.uq.oz.au (Nirad Sharma) writes:
>> Is it possible to write Prolog progams and have them integrated into a c
>> program ?  I seem to remember that Turbo Prolog on the PC platform allows
>> this.  I am looking for a Unix (SYSV) solution which would allow prolog
>> units to be written and either compiled and linked to the c code or be
>> interpreted at run-time.  Some extensive logic needs to be built into some
>> algorithms that I am using for a database application. While I have already
>> coded some of this logic in c I would prefer to convert the existing and
>> the future code to prolog for ease of programming and verification.

On a PC, it is certainly possible to call Arity Prolog predicates from
Microsoft C.  The prolog does not neccessarily all need to be compiled,
some of it can be consulted in at run time.  You can also call the
Prolog from other MS language implementations such as Fortran if you get
them to call C first. 

Another (PC) option would be to run your C program under Windows3 and
get it to operate a Windows based Prolog that supports DDE.  Prolog-2
for Windows can do this. 

Olly  Morgan
--
----------------------------------------------------------------------------
 Olly Morgan @ Scottish Agricultural College,  Edinburgh EH9 2HH, Scotland
               Tel: (+44 31) 662 4395          E.Mail: O.Morgan@ed.ac.uk
----------------------------------------------------------------------------

ted@nmsu.edu (Ted Dunning) (05/27/91)

In article <1991May26.231138.13000@brolga.cc.uq.oz.au> exnirad@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.

campbell@dataco.UUCP (Duncan Campbell) (05/28/91)

PDC Prolog, the successor to Turbo Prolog, runs on SCO System V 3.2
(and several other platforms) and allows for embedded prolog functions
in C.

Duncan Campbell



***--------------------------------------------------------------***
* DISCLAIMER:                                                      *
* ==========:                                                      *
*    The opinions expressed are solely of the author and do not    *
*    necessarily reflect the opinions of Canadian Marconi Company. *
***--------------------------------------------------------------***

ted@nmsu.edu (Ted Dunning) (05/30/91)

In article <644@fudd.dataco.UUCP> campbell@dataco.UUCP (Duncan Campbell) writes:

   PDC Prolog, the successor to Turbo Prolog, runs on SCO System V 3.2
   (and several other platforms) and allows for embedded prolog functions
   in C.


when referencing turbo `prolog' (by any name), quotes should be put
around the word prolog to indicate that you know that it isn't really
prolog.  


turbo `prolog' does allow for embedding, it just doesn't allow one to
embed calls to prolog in c.
--
	Offer void except where prohibited by law.

shankar@hpcupt3.cup.hp.com (Shankar Unni) (06/03/91)

In comp.lang.c, exnirad@brolga.cc.uq.oz.au (Nirad Sharma) writes:

> Is it possible to write Prolog progams and have them integrated into a c
> program ?  I seem to remember that Turbo Prolog on the PC platform allows
> this.  I am looking for a Unix (SYSV) solution which would allow prolog
> units to be written and either compiled and linked to the c code or be
> interpreted at run-time.  Some extensive logic needs to be built into some
> algorithms that I am using for a database application. While I have already
> coded some of this logic in c I would prefer to convert the existing and
> the future code to prolog for ease of programming and verification.

ZYX Prolog supports exactly this kind of facility. It has a complete
foreign-function interface to Prolog, allowing calls both ways (C -> Prolog
and vice versa), and the main program can be either C or Prolog.

It seemsd to be available on a wide variety of Unix platforms.

Contact ZYX AB at +468-6653205 (I think..).
-----
Shankar Unni                                   E-Mail:
HP India Software Operation, Bangalore       Internet: shankar@india.hp.com
Phone : +91-812-261254 x417                      UUCP: ...!hplabs!hpda!shankar