use of org.jpl7.Term in project packages-jpl by SWI-Prolog.
the class Term method putParams.
/**
* This internal method is public because it needs to be callable via JNI, but it is not part of JPL's public API
* and should not be used by applications.
*
* @param ps
* @return
* @throws JPLException
* if there are more actual than formal parameters.
*/
public Term putParams(Term[] ps) {
// necessarily (?) public
IntHolder next = new IntHolder();
next.value = 0;
Term t2 = this.putParams1(next, ps);
if (next.value != ps.length) {
throw new JPLException("more actual params than formal");
}
return t2;
}
use of org.jpl7.Term in project packages-jpl by SWI-Prolog.
the class Query method close.
/**
* This method can be used to close an open query before its solutions are
* exhausted. It is called automatically when solutions are exhausted.
* Calling close() on an already closed Query has no effect.
* <p>
*
* Here is one way to get the first three solutions to a Query:
*
* <pre>
* Query q = new Query(predicate, args);
* Map<String, Term> sub1 = q.nextSolution();
* Map<String, Term> sub2 = q.nextSolution();
* Map<String, Term> sub3 = q.nextSolution();
* q.close();
* </pre>
* <p>
*/
public final void close() {
if (!open) {
// it is not an error to attempt to close a closed Query
return;
}
if (Prolog.thread_self() == -1) {
throw new JPLException("no engine is attached to this thread");
}
if (Prolog.current_engine().value != engine.value) {
throw new JPLException("this Query's engine is not that which is attached to this thread");
}
qid_t topmost = Prolog.current_query();
if (topmost.value != this.qid.value) {
throw new JPLException("this Query (" + this.hashCode() + ":" + this.toString() + ") is not topmost (" + topmost.hashCode() + ":" + topmost.toString() + ") within its engine[" + engine.value + "]");
}
Prolog.close_query(qid);
// for tidiness
qid = null;
org.jpl7.fli.Prolog.discard_foreign_frame(fid);
// for tidiness
fid = null;
if (Prolog.current_query() == null) {
// only Query open in this engine?
if (Prolog.current_engine_is_pool()) {
// this (Query's) engine is
// from the pool?
Prolog.release_pool_engine();
// System.out.println("JPL releasing engine[" + engine.value +
// "]");
} else {
// System.out.println("JPL leaving engine[" + engine.value +
// "]");
}
} else {
// System.out.println("JPL retaining engine[" + engine.value + "]
}
// this Query is now closed
open = false;
// this Query, being closed, is no longer associated with
engine = null;
// any Prolog engine
}
use of org.jpl7.Term in project packages-jpl by SWI-Prolog.
the class Family method main.
public static void main(String[] argv) {
Query q1 = new Query("consult", new Term[] { new Atom("jpl/test/family.pl") });
System.err.println("consult " + (q1.hasSolution() ? "succeeded" : "failed"));
for (int i = 0; i < 20; i++) {
System.out.println("spawning client[" + i + "]");
new Family(i).start();
}
}
use of org.jpl7.Term in project packages-jpl by SWI-Prolog.
the class TestJUnit method testIsJVoid1.
public void testIsJVoid1() {
Term t = Query.oneSolution("X = @(void)").get("X");
assertTrue("@(void) . isJVoid() succeeds", t.isJVoid());
}
use of org.jpl7.Term in project packages-jpl by SWI-Prolog.
the class TestJUnit method testIsJVoid2.
public void testIsJVoid2() {
Term t = Query.oneSolution("X = @(3)").get("X");
assertFalse("@(3) . isJVoid() fails", t.isJVoid());
}
Aggregations