PrologJ includes an API which allows Java code to access the Prolog database
and to call code written in Prolog. Java objects are converted to the
classes used internally by the PrologJ implementation.
This API resides in the class
prologj.PrologJ, and also makes use of the classes
prologj.PrologBoundTerm, prologj.PrologContinuation,
prologj.PrologException, prologj.PrologCompound and
prologj.PrologList. Complete
javadoc documentation is available
for the class PrologJ and all the other classes it uses.
asserta()assertz()call()retract()retractall()PrologBoundTerm
interface, or by a string that represents the term in standard Prolog
textual form. call and retract).
The methods that correspond to these include versions that take a second
parameter that implements the
PrologContinuation interface. This parameter provides a mechanism
for accessing the bindings of variables that made an operation succeed, and
for redoing an operation. The one-parameter versions of these methods only
succeed once and don't provide any mechanism for accessing the bindings of
variables.
makeBoundTerm()
consult()reconsult()interpret()listing()current_input or a PrintWriter to be established as
current_output for future all input or output operations, until
another stream replaces it. These methods are analogous to the standard Prolog
predicates of the same name.
set_input()set_output()setBuiltinPredicateCategories()
The PrologJ API defines the concept of a bound term object, which encapsulates
a Prolog term, together with information about the bindings of variables
occurring within it. A bound term object is constructed from the textual
representation of a Prolog term, either by explicit use of the
makeBoundTerm() method of class PrologJ, or implicitly by
using the textual representation of a Prolog term (represented by a
String as a parameter to one of the methods of the API). Also, when
a method that can bind variables (call or retract)
succeeds , information about the variable bindings is encapsulated
in a bound term object that is passed as a parameter to the succeed()
method of the continuation object passed
to the method call.
The capabilities of a bound term object are specified by the interface
PrologBoundTerm.
asserta, assertz, call,
retract or retractall).java.sql.PreparedStatement).
call or
retract has succeeded - i.e. when the bound term object
is received as a parameter to the succeed method of some
continuation.
The PrologJ API defines the concept of a continuation, which allows operations
to succeed multiple times. The API includes versions of the methods
call and retract which take a continuation
parameter.
The capabilities of a continuation object are specified by the interface
PrologContinuation.
This interface specifies a single method of return type boolean
which is called each time the operation
succeeds. This method takes a single parameter which fulfills the
BoundPrologTerm interface, and thus allows access to the bindings
of variables that resulted in success. It returns false if it
wants the implementation to try to find another way of satisfying the original
goal, and true if to request no further attempts at re-doing
the goal (in which case the original call or retract
method returns true to its original caller.