Next: , Previous: , Up: lib-jasper   [Contents][Index]


10.19.4 Jasper Package Class Reference

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 (https://sicstus.sics.se/documentation.html).

Please note: None of the se.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 how se.sics.jasper worked 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 in SICStus Prolog Release Notes for limitations in multi threaded Jasper.

Method on SICStus: boolean query (String module, String name, SPTerm args[])

Call name with args (a vector of SPTerm objects). Like once(Module:Name(Args…)).

Returns true if the call succeeded, false if the call failed, i.e. there were no solutions.

Introduced in release 3.8.5.

Method on SICStus: boolean query (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 release 3.8.5.

Method on SICStus: boolean query (SPPredicate pred, SPTerm args[])

Obsolescent version of SICStus::query() above.

Method on SICStus: boolean queryCutFail (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.

Method on SICStus: boolean queryCutFail (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 details

Introduced in release 3.8.5.

Method on SICStus: boolean queryCutFail (SPPredicate pred, SPTerm args[])

Obsolescent version of queryCutFail above.

Method on SICStus: SPQuery openQuery (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.

Method on SICStus: boolean openQuery (String goal, Map varMap)

Sets up a query specified as a string. See openQuery and query for details.

Introduced in release 3.8.5.

Method on SICStus: SPQuery openQuery (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 runtime system that no more answers are required.

Method on SPQuery: boolean nextSolution ()

Obtain the next solution. Returns true on success and false if there were no more solutions. When you are no longer interested in any more solutions, you should call SPQuery.close or SPQuery.cut to close the query.

Returns true if a new solution was produced, false if there were no more solutions. This corresponds roughly to fail/0. See SPTerm and Memory for additional details.

Method on SPQuery: close ()

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.

Method on SPQuery: cut ()

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.



Send feedback on this subject.