Detailed documentation of the classes in the jasper
package can
be found in the HTML documentation installed with SICStus and also at
the SICStus documentation page
(http://www.sics.se/sicstus/docs/).
Please note: None of these.sics.jasper
methods are thread safe, unless explicitly mentioned, they can only be called from the thread that created the SICStus object. (This is different from howse.sics.jasper
worked in SICStus 3.8)
However, Jasper in SICStus 3.9 and later supports multi threaded mode. Several Java threads can access SICStus runtime through a server thread that does the actual calls.
The API is defined by three interfaces
: Prolog
,
Query
and Term
. The methods of these interfaces
are
implemented by inner classes of the Jasper
server. Instances of these
inner classes are returned by methods of the class Jasper
and
can then be used from multiple threads by the Java programmer.
In multi threaded mode the Java programmer obtains an object
implementing the interface Prolog
. That interface has methods
similar to the methods of the SICStus
class described below.
Interface Query
and interface Term
have the same
relations to class SPQuery
and class SPTerm
, respectively.
In addition the SICStus
class, the SPQuery
class and the
SPTerm
class all implement the above interfaces. The methods of
the interfaces are preferred over the old methods.
See the HTML documentation for details on the methods of the interfaces
.
See Jasper Notes, for limitations in multi threaded Jasper.
(String module, String name, SPTerm args[])
Call name with args (a vector of
SPTerm
objects). Likeonce(Module:Name(Args...))
.Returns
true
if the call succeeded,false
if the call failed, i.e. there were no solutions.Introduced in SICStus 3.8.5.
(String goal, Map varMap)
Call a goal specified as a string.
goal
- The textual representation of the goal to execute, with terminating period.
varMap
- A map from variable names to SPTerm objects. Used both for passing variable bindings into the goal and to obtain the bindings produced by the goal. May be null.
On success, the values of variables with names that do not start with underscore (`_') will be added to the map.
Returns
true
if the call succeeded,false
if the call failed, i.e. there were no solutions.HashMap varMap = new HashMap(); varMap.put("File", new SPTerm(sp, "datafile.txt")); if (sp.query("see(File),do_something(Result),seen.", varMap)) { System.out.println("Result==" + ((SPTerm)varMap.get("Result")).toString()); } else { System.out.println("Failed); }Introduced in SICStus 3.8.5.
(SPPredicate pred, SPTerm args[])
Obsolescent version of
SICStus::query()
above.
(String module, String name, SPTerm args[])
Call name with args for side-effect only.
As
SICStus.query()
it only finds the first solution, and then it cuts away all other solutions and fails.It corresponds roughly to the following Prolog code:
( \+ call(Module:Name(Args...)) -> fail; true )Introduced in SICStus 3.8.5.
(String goal, Map varMap)
Call a goal specified as a string, for side-effect only. The map is only used for passing variable bindings into the goal. See
query
for detailsIntroduced in SICStus 3.8.5.
(SPPredicate pred, SPTerm args[])
Obsolescent version of
queryCutFail
above.
(String module, String name, SPTerm args[])
Sets up a query (an object of class
SPQuery
), which can later be asked to produce solutions. You must close an opened query when no more solutions are required; see below.It corresponds roughly to the following Prolog code:
( true % just calling openQuery does not call the predicate ; % failing (nextSolution) will backtrack for more solutions call(Module:Name(Args...)) )Introduced in SICStus 3.8.5.
(String goal, Map varMap)
Sets up a query specified as a string. See
openQuery
andquery
for details.Introduced in SICStus 3.8.5.
(SPPredicate pred, SPTerm args[])
Obsolescent version of
openQuery
above.
The following methods are used to obtain solutions from an opened query and to tell the SICStus run-time system that no more answers are required.
Obtain the next solution. Returns
true
on success andfalse
if there were no more solutions. When you are no longer interested in any more solutions, you should callSPQuery.close
orSPQuery.cut
to close the query.Returns
true
if a new solution was produced,false
if there were no more solutions. This corresponds roughly tofail/0
. See SPTerm and Memory, for additional details.
Cut and fail away any previous solution to the query. After closing a query object, you should not use it anymore. This corresponds roughly to
!, fail
. See SPTerm and Memory, for additional details.
Cut, but do not fail away, any previous solution. After closing a query object with
cut
, you should not use it anymore. This corresponds roughly to!
. See SPTerm and Memory, for additional details.