From ovidiu@orion.rgv.hp.com  Fri Jan 21 23:14:00 2000
Received: from bbnona4.hp.com (bbnrel4.net.external.hp.com [155.208.254.68])
	by swi.psy.uva.nl (8.9.3/8.9.3) with ESMTP id XAA26893;
	Fri, 21 Jan 2000 23:14:00 +0100 (MET)
Received: from orion.rgv.hp.com (root@orion.rgv.hp.com [15.81.94.166])
	by bbnona4.hp.com (8.8.6/8.8.5tis) with ESMTP id XAA19324;
	Fri, 21 Jan 2000 23:14:00 +0100 (MET)
Received: (from ovidiu@localhost)
	by orion.rgv.hp.com (8.9.3/8.9.3) id OAA23473;
	Fri, 21 Jan 2000 14:12:44 -0800
Message-Id: <200001212212.OAA23473@orion.rgv.hp.com>
X-Mailer: exmh version 2.1.0 04/14/1999
To: Fred Dushin <fadushin@syr.edu>
Cc: Jan Wielemaker <jan@swi.psy.uva.nl>, prolog@swi.psy.uva.nl
Subject: Prolog foreign predicates in Prolog (was Re: problem with JPL 1.0.1 
 and SWI Prolog 3.3.0)
In-Reply-To: Your message of "Fri, 21 Jan 2000 15:47:52 EST."
             <3888C5F8.2550C811@syr.edu> 
X-Url: http://www.geocities.com/SiliconValley/Monitor/7464/
X-Image-Url: http://www.geocities.com/SiliconValley/Monitor/7464/ovidiu.tiff
X-Face: ?(@Y~qjBA}~8ZMh5gM4{Q{bE_*:sCJ3@Z?{B*Co=J!#8bb~-z?-0._vJjt~MM59!MjxG%>U
 5>MW^2-\7~z04buszR^=m^U|m66>FdR@cFwhb;.A(8*D.QmLkK]z,md0'HiOE\pyeiv_PACR+P:Cm.
 wq_%l':E:q]g-UCc>r&s@BVo'kFN;(\9PF22Myg5w%nUBWQ6MJJ#qL#w>2oxckP'H:\$9F"mxsz]Dg
 k{1`fTcP'Y$CgGnc^paTV$dzhVX<SVN1RPb="gz3>+;(U$;Eb)P<>G)g)
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Date: Fri, 21 Jan 2000 14:12:44 -0800
From: Ovidiu Predescu <ovidiu@cup.hp.com>

On Fri, 21 Jan 2000 15:47:52 -0500, Fred Dushin <fadushin@syr.edu> wrote:

> > I have one question about SWI Prolog/JPL integration: is it possible to define
> > foreign predicates in Java that could be called from Prolog? I know that I can
> > call Prolog predicates from Java, but I didn't see anything in the
> > documentation about the other way around.
> 
> This has not been implemented (yet).  It gets to the question I just posted to
> the list: Do people *want* to see this feature?  And if so, what ideas do you
> have about what the interfaces and architecture should be like?
> 
> I'm not sure how rich the reflection APIs are in Java to make this feasible.
> Remember, there are no predicates to call in Java.  There are classes and class
> instances, but it's not clear how to proceed from there.  The nice thing about
> going from Java to Prolog is that you have a nice term structure that everything
> in Prolog fits nicely into.  But the reverse direction is not as clear to me. 
> The closest thing to me seems to be Java Reflection, since you can traverse the
> Java type structure using it.  But it's still not clear to me how this could be
> useful.
> 
> I'm throwing these ideas out there to stimulate discussion.  I haven't been
> thinking to heavily about this direction lately, and I'm just curious if anyone
> has any ideas about what it should look like (no less how it should function).
> 
> Does anyone know even if this sort of thing has been done elsewhere?

I think this feature would definitely be useful because you can have access to
virtually all the features the Java frameworks provide. For example to get
database access in Prolog you can simply write a predicate interface to JDBC
and you get access to it. I think such a feature would open up an incredible
perspective as you can implement all sorts of unexpected features in Prolog.

There are two ways I can see to support Java foreign predicates. We can come up
with a special interface that has to be adopted by a Java class that wants some
of its methods to act as foreign predicates. Then one way of doing things is to
explicitly register these classes or instances of these classes as foreign
predicates. Another is, as you mention, to use the Java reflection capabilities
to get access to these classes. I prefer the first choice as it gives more
control to the programmer.

Regards,
Ovidiu

-- 
Ovidiu Predescu <ovidiu@cup.hp.com>
http://orion.rgv.hp.com/  (inside HP's firewall only)
http://www.geocities.com/SiliconValley/Monitor/7464/


