Mixing Java and Prolog
SICStus Prolog supports two different ways of interfacing a Prolog program with
a Java program: Jasper and PrologBeans. These two
packages are quite different, and the programmer is well advised to
carefully consider which package is best suited to her needs.
Jasper is "tightly coupled" with Prolog, which means that everything
runs in the same process (the necessary code is loaded at runtime via
dynamic linking). PrologBeans, on the other hand, is "loosely
coupled", which means that the Java code runs in a different process
from the Prolog code. In fact, the Java program and the Prolog program
can run on separate machines, since the communication is done via
TCP/IP sockets.
Advantages of Jasper:
- Jasper is bi-directional. Callbacks are possible (limited in levels only by
memory), and queries can backtrack.
- Jasper is normally faster than PrologBeans.
Advantages of PrologBeans:
- Since the Java program and the Prolog program run in separate
processes, there is no competition for memory between the Java Virtual
Machine and the Prolog Abstract Machine. This means that PrologBeans
works well with large applications.
- Distribution over a network is a no-brainer when using PrologBeans. The
application is distributable from the beginning.
- PrologBeans has support for user session handling both at the Java level
(with support for HTTP sessions and JNDI lookup) and at the Prolog
level. This makes it easy to integrate Prolog applications into
applications based on Java servers.