[comp.lang.prolog] A question about Quintus and external lang interfaces

russo@caip.rutgers.edu (Mark F. Russo) (06/28/89)

I have a question about Quintus Prolog and the latest functionality of
the external language interface.  I know that you can install a C
function as a predicate call in a Quintus Prolog program.  My question
is, can you then make a query back into the prolog database from that
external C function.  This is currently possible using BIM_Prolog.

Are there any other prologs with which this can be done?

Mark
-- 

uucp:   {from.anywhere}!rutgers!caip.rutgers.edu!russo
arpa:   russo@caip.rutgers.edu
or
uucp:   {from.anywhere}!rutgers!petsd!pedsga!ccscg!markr
arpa:	markr@ccscg.tinton.ccur.com

zhu@ogccse.ogc.edu (Jianhua Zhu) (06/29/89)

In article <Jun.27.14.28.58.1989.250@caip.rutgers.edu> russo@caip.rutgers.edu (Mark F. Russo) writes:
>I have a question about Quintus Prolog and the latest functionality of
>the external language interface.  I know that you can install a C
>function as a predicate call in a Quintus Prolog program.  My question
>is, can you then make a query back into the prolog database from that
>external C function.

I have used Quintus Prolog version 2.0 (which may not be the latest
version) on Tektronix UTEK machines.  As far as I know, you can not
call back into prolog from a foregn language routine directly.  However,
you can achieve this effect indirectly.

In addition to foreign language interfaces, Quintus Prolog also provides
a set of IPC libraries that allow you to run multiple processes
communicating with each other.  In particular, you can have a C master
process and a Prolog servant process running at the same time, and you
can call Prolog predicates from the C process.

The following scheme would provide you with one way to indirectly
implement the kind of invocation pattern you described (a rather
painful indirection, though):

+------------+-------+        +-------+------------+
|            | IPC-1 |<======>| IPC-1 |   Prolog   |
|     C      +-------|        +-------+   Servant  |
|  Master            |        |           Process  |
|  Process   +-------+        +-------+---------+  |
|            | IPC-2 |<======>| IPC-2 |  C      |  |
+------------+-------+        +-------+ Foreign |  |
                              |        Routines |  |
                              +-----------------+--+

where IPC-1 is the system provided IPC facility, IPC-2 is a different set
of communication routines you have to write yourself.

-- 
 /__|__  _/-\_ |  /__|__   Jianhua Zhu              UUCP : tektronix!ogccse!zhu
"___|__,  --- || /| ,|_/   CSE Dept -- OGC          CSNet: zhu@cse.ogc.edu
  ,"|",   \|/ || ---+---   19600NW von Neumann Dr   Phone: (503) 690-1121 x7395
 / \|  \ /--- \|    |      Beaverton, OR 97006

anjo@swivax.UUCP (Anjo Anjewierden) (06/30/89)

russo@caip.rutgers.edu (Mark F. Russo) writes:
>
>I have a question about Quintus Prolog and the latest functionality of
>the external language interface.  I know that you can install a C
>function as a predicate call in a Quintus Prolog program.  My question
>is, can you then make a query back into the prolog database from that
>external C function.  This is currently possible using BIM_Prolog.

Your observations are correct.  Not being able to call Prolog goals
from an external language (e.g. C) is one of the few things missing
in Quintus Prolog.  The only solution until Quintus provides this
feature is to write a small interpreter that eats Prolog goals in
small pieces (atoms, integers and floats) and reconstructs the goal
in Prolog itself.  We actually use this method, although it remains
a kludge.  We previously used the IPC method, but performance then
becomes unpredictable (on Sun workstations) because of swapping.

>Are there any other prologs with which this can be done?

BIM_Prolog as you mentioned.  SWI-Prolog (contact jan@swivax.uucp)
provides a collection of C functions to construct and call goals
from C in a fashion similar to BIM_Prolog.

-- Anjo.