Search in sources :

Example 11 with Term

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;
}
Also used : IntHolder(org.jpl7.fli.IntHolder)

Example 12 with Term

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&lt;String, Term&gt; sub1 = q.nextSolution();
 * Map&lt;String, Term&gt; sub2 = q.nextSolution();
 * Map&lt;String, Term&gt; 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
}
Also used : org.jpl7.fli.qid_t(org.jpl7.fli.qid_t)

Example 13 with Term

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();
    }
}
Also used : Query(org.jpl7.Query) Atom(org.jpl7.Atom)

Example 14 with Term

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());
}
Also used : Term(org.jpl7.Term)

Example 15 with Term

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());
}
Also used : Term(org.jpl7.Term)

Aggregations

Term (org.jpl7.Term)62 Query (org.jpl7.Query)42 Variable (org.jpl7.Variable)24 Atom (org.jpl7.Atom)21 Compound (org.jpl7.Compound)21 Map (java.util.Map)12 BigInteger (java.math.BigInteger)6 Integer (org.jpl7.Integer)6 org.jpl7.fli.term_t (org.jpl7.fli.term_t)4 Term (org.apache.cassandra.cql3.Term)3 MarshalException (org.apache.cassandra.serializers.MarshalException)3 PrologException (org.jpl7.PrologException)3 JPLException (org.jpl7.JPLException)2 IntHolder (org.jpl7.fli.IntHolder)2 URL (java.net.URL)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 TestSuite (junit.framework.TestSuite)1 DoubleHolder (org.jpl7.fli.DoubleHolder)1 Int64Holder (org.jpl7.fli.Int64Holder)1 ObjectHolder (org.jpl7.fli.ObjectHolder)1