From fadushin@syr.edu  Sat Jan 22 17:12:38 2000
Received: from fadushin.ne.mediaone.net (fadushin.ne.mediaone.net [24.218.120.90])
	by swi.psy.uva.nl (8.9.3/8.9.3) with ESMTP id RAA05305
	for <prolog@swi.psy.uva.nl>; Sat, 22 Jan 2000 17:12:37 +0100 (MET)
Received: from syr.edu (localhost [127.0.0.1])
	by fadushin.ne.mediaone.net (8.9.3/8.9.3) with ESMTP id LAA01642;
	Sat, 22 Jan 2000 11:16:27 -0500
Sender: fadushin@fadushin.ne.mediaone.net
Message-ID: <3889D7D5.24A7476C@syr.edu>
Date: Sat, 22 Jan 2000 11:16:21 -0500
From: Fred Dushin <fadushin@syr.edu>
Organization: Adiron, LLC
X-Mailer: Mozilla 4.7 [en] (X11; I; Linux 2.2.14 ppc)
X-Accept-Language: en
MIME-Version: 1.0
To: Philip Lafeber <lafeber@solveware.nl>
CC: prolog@swi.psy.uva.nl
Subject: Re: Interfacing Java and Prolog both ways
References: <200001211951.LAA22973@orion.rgv.hp.com> <3888C5F8.2550C811@syr.edu> <002a01bf64cb$ccceb220$fe0aa8c0@willi.nl>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

> Yes indeed! We have just been working on a system in which Java is the motor
> behind an 'intelligent' web application, which calls Prolog for some
> reasoning tasks. But then Prolog calls back on the Java program to ask for
> SQL-queries in an Access-database, since we weren't able to call to the
> database directly.
> We are working in B-Prolog, which is largely the same as SWI-Prolog. The
> Java program incorporates a an object called prologinterface, which consists
> of a function that call Prolog, called 'askQuestion' (asks Prolog to
> interpret a written Dutch sentence), and several functions that can be
> called by Prolog, like 'returnOutput' (delivers output in string format to
> the output stream) and 'selectDBQuery' (takes paramaters from Prolog to
> construct an SQL-query, then returns the result in a certain format to
> Prolog).

I see how that can be useful, but it looks like your selectDBQuery has to be
coded directly into C, whose implementation then calls the JNI to get an
instance of some class (perhaps as a static/globally accessible structure),
marshalls the data from Prolog engine into arguments for some Java class method,
and then makes the call to the method (which I presume then uses the JDBC to
send and receive SQL queries).

That's fine, but what I am after is a general enough interface so that Java
classes and methods can be invoked seamlessly from Prolog without the user
having to touch any C.  This, after all, is what JPL provides in the opposite
direction.  Unfortunately, the only way I can see to do this would be to
implement the JNI as a set of foreign predicates.  This is a rather large
undertaking, however, and it would be incredibly cumbersome on the programmer.

Another idea is to think about alternative technologies.  CORBA is one that
comes to mind; it provides a language-neutral way to write interfaces between
different languages.  To my knowledge, there is no (standard) Prolog mapping
from IDL, though, so that is something that would need some thought, though it
looks like Jan has covered some of that territory.  But having an ORB in the
Prolog engine would be pretty nice.  It would actually make JPL unecessary
(insofar as it is necessary at all...)  But I can also see how Prolog purists
might scoff at the idea.  I can't see non-deterministic CORBA calls going over
so well.

Jan, any status on your work with CORBA and Prolog?  I saw your online paper,
but I wasn't sure where you had taken that work.

Fred

