Detailed documentation of the classes in the jasper package can
be found in the HTML documentation installed with SICStus and also on
the SICStus documentation page
(http://sicstus.sics.se/documentation.html).
Please note: None of these.sics.jaspermethods 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.jasperworked in release 3.8.)
As of release 3.9, Jasper 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
SPTermobjects). Likeonce(Module:Name(Args...)).Returns
trueif the call succeeded,falseif the call failed, i.e. there were no solutions.Introduced in release 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 don't start with underscore (‘_’) will be added to the map.
Returns
trueif the call succeeded,falseif 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 release 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 release 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
queryfor detailsIntroduced in release 3.8.5.
(SPPredicate pred, SPTerm args[])Obsolescent version of
queryCutFailabove.
(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 release 3.8.5.
(String goal, Map varMap)Sets up a query specified as a string. See
openQueryandqueryfor details.Introduced in release 3.8.5.
(SPPredicate pred, SPTerm args[])Obsolescent version of
openQueryabove.
The following methods are used to obtain solutions from an opened query and to tell the SICStus runtime system that no more answers are required.
Obtain the next solution. Returns
trueon success andfalseif there were no more solutions. When you are no longer interested in any more solutions, you should callSPQuery.closeorSPQuery.cutto close the query.Returns
trueif a new solution was produced,falseif 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 don't 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.