use of org.jpl7 in project packages-jpl by SWI-Prolog.
the class Term method putTerms.
/**
* This static method converts an array of Terms to a *consecutive* sequence of term_t objects. Note that the first
* term_t object returned is a term_t class (structure); the succeeding term_t objects are consecutive references
* obtained by incrementing the *value* field of the term_t.
*
* @param varnames_to_vars
* Map from variable names to JPL Variables.
* @param args
* An array of org.jpl7.Term references.
* @return consecutive term_t references (first of which is a structure)
*/
protected static term_t putTerms(Map<String, term_t> varnames_to_vars, Term[] args) {
// First create a sequence of term_ts.
// The 0th term_t will be a org.jpl7.fli.term_t.
// Successive Prolog term_t references will reside in the Prolog engine, and can be obtained by term0.value+i.
term_t term0 = Prolog.new_term_refs(args.length);
// For each new term ref, construct a Prolog term by putting an appropriate Prolog type into the ref.
long ith_term_t = term0.value;
for (int i = 0; i < args.length; ++i, ++ith_term_t) {
term_t term = new term_t();
term.value = ith_term_t;
// each subclass defines its own put()
args[i].put(varnames_to_vars, term);
}
return term0;
}
use of org.jpl7 in project packages-jpl by SWI-Prolog.
the class Family method run.
public void run() {
Map<String, Term> solution;
Variable X = new Variable("X");
// --------------------------------------------------
Query q2 = new Query("child_of", new Term[] { new Atom("joe"), new Atom("ralf") });
System.err.println("child_of(joe,ralf) is " + (q2.hasSolution() ? "provable" : "not provable"));
new Query("sleep", new Term[] { new org.jpl7.Integer(delay) }).hasSolution();
// --------------------------------------------------
Query q3 = new Query("descendent_of", new Term[] { new Atom("steve"), new Atom("ralf") });
System.err.println("descendent_of(steve,ralf) is " + (q3.hasSolution() ? "provable" : "not provable"));
new Query("sleep", new Term[] { new org.jpl7.Integer(delay) }).hasSolution();
// --------------------------------------------------
Query q4 = new Query("descendent_of", new Term[] { X, new Atom("ralf") });
solution = q4.oneSolution();
System.err.println("first solution of descendent_of(X, ralf)");
System.err.println("X = " + solution.get(X.name));
new Query("sleep", new Term[] { new org.jpl7.Integer(delay) }).hasSolution();
// --------------------------------------------------
Map<String, Term>[] solutions = q4.allSolutions();
System.err.println("all solutions of descendent_of(X, ralf)");
for (int i = 0; i < solutions.length; i++) {
System.err.println("X = " + solutions[i].get(X.name));
}
new Query("sleep", new Term[] { new org.jpl7.Integer(delay) }).hasSolution();
// --------------------------------------------------
System.err.println("each solution of descendent_of(X, ralf)");
while (q4.hasMoreSolutions()) {
solution = q4.nextSolution();
System.err.println("X = " + solution.get(X.name));
}
new Query("sleep", new Term[] { new org.jpl7.Integer(delay) }).hasSolution();
// --------------------------------------------------
Variable Y = new Variable("Y");
Query q5 = new Query("descendent_of", new Term[] { X, Y });
System.err.println(id + ": each solution of descendent_of(X, Y)");
while (q5.hasMoreSolutions()) {
solution = q5.nextSolution();
System.err.println(id + ": X = " + solution.get(X.name) + ", Y = " + solution.get(Y.name));
new Query("sleep", new Term[] { new org.jpl7.Integer(delay) }).hasSolution();
}
}
use of org.jpl7 in project packages-jpl by SWI-Prolog.
the class Test_Integer method testBigInteger2.
@Test
public void testBigInteger2() {
BigInteger b = new BigInteger("12345678901234567890123456789");
// too big for a long
Term i = new Integer(b);
Term g = new Compound("is", new Term[] { new Variable("X"), i });
Term x = Query.oneSolution(g).get("X");
assertTrue("X is an org.jpl7.Integer", x.isInteger());
assertTrue("X is a big org.jpl7.Integer", x.isBigInteger());
assertEquals("X's value is as expected", x.bigValue(), b);
}
use of org.jpl7 in project packages-jpl by SWI-Prolog.
the class Test_Report method reportConfiguration.
@Test
public void reportConfiguration() {
System.out.println("\t JPL testing under the following configuration:");
// Query.hasSolution("use_module(library(jpl))"); // only because we call e.g. jpl_pl_syntax/1 below
useJPLmodule();
Term swi = Query.oneSolution("current_prolog_flag(version_data,Swi)").get("Swi");
System.out.println("\t swipl.version = " + swi.arg(1) + "." + swi.arg(2) + "." + swi.arg(3));
// This is the problematic one as it wil trigger loading library(jpl)
System.out.println("\t swipl.syntax = " + Query.oneSolution("jpl_pl_syntax(Syntax)").get("Syntax"));
System.out.println("\t swipl.home = " + Query.oneSolution("current_prolog_flag(home,Home)").get("Home").name());
System.out.println("\t jpl.jar = " + JPL.version_string());
System.out.println("\t jpl.dll = " + org.jpl7.fli.Prolog.get_c_lib_version());
System.out.println("\t jpl.pl = " + Query.oneSolution("jpl_pl_lib_version(V)").get("V").name());
System.out.println("\t java.version = " + System.getProperty("java.version"));
System.out.println("\t java_lib_version = " + JPL.version_string());
System.out.println("\t c_lib_version = " + org.jpl7.fli.Prolog.get_c_lib_version());
System.out.println("\t pl_lib_version = " + Query.oneSolution("jpl:jpl_pl_lib_version(V)").get("V").name() + " " + Query.oneSolution("module_property(jpl, file(F))").get("F").name());
System.out.println("\t os.name = " + System.getProperty("os.name"));
System.out.println("\t os.arch = " + System.getProperty("os.arch"));
System.out.println("\t os.version = " + System.getProperty("os.version"));
}
use of org.jpl7 in project packages-jpl by SWI-Prolog.
the class FamilyMT method run.
public void run() {
Map<String, Term> solution;
// Variable X = new Variable("X");
//
Query q2 = new Query("child_of(joe,ralf)");
System.err.println("child_of(joe,ralf) is " + (q2.hasSolution() ? "provable" : "not provable"));
new Query("sleep(?)", new Term[] { new org.jpl7.Integer(delay) }).hasSolution();
//
Query q3 = new Query("descendent_of(steve,ralf)");
System.err.println("descendent_of(steve,ralf) is " + (q3.hasSolution() ? "provable" : "not provable"));
delay();
//
Query q4 = new Query("descendent_of(X, ralf)");
solution = q4.oneSolution();
System.err.println("first solution of descendent_of(X, ralf)");
System.err.println("X = " + solution.get("X"));
delay();
//
Map<String, Term>[] solutions = q4.allSolutions();
System.err.println("all solutions of descendent_of(X, ralf)");
for (int i = 0; i < solutions.length; i++) {
System.err.println("X = " + solutions[i].get("X"));
}
delay();
//
System.err.println("each solution of descendent_of(X, ralf)");
while (q4.hasMoreSolutions()) {
solution = q4.nextSolution();
System.err.println("X = " + solution.get("X"));
}
delay();
//
Query q5 = new Query("descendent_of(X, Y)");
System.err.println(id + ": each solution of descendent_of(X, Y)");
while (q5.hasMoreSolutions()) {
solution = q5.nextSolution();
System.err.println(id + ": X = " + solution.get("X") + ", Y = " + solution.get("Y"));
delay();
}
}
Aggregations