Search in sources :

Example 1 with PrologException

use of org.jpl7.PrologException in project packages-jpl by SWI-Prolog.

the class Test method test_11.

static void test_11() {
    System.out.print("test 11...");
    Term tuple = new Compound("t", new Term[] { new Atom("a"), new Atom("b"), new Atom("c"), new Atom("d"), new Atom("e") });
    try {
        Variable X = new Variable("X");
        Query q11 = new Query("tuple", new Term[] { X });
        Term result = q11.oneSolution().get("X");
        if (result == null || !result.equals(tuple)) {
            System.out.println("failed:");
            System.out.println("\tresult: " + result);
            System.out.println("\ttuple:  " + tuple);
        // System.exit(1);
        }
        if (result.arg(1) == null || !result.arg(1).equals(new Atom("a"))) {
            System.out.println("failed:");
            System.out.println("\tresult.arg(1): " + result.arg(1));
        // System.exit(1);
        }
        if (result.arg(2) == null || !result.arg(2).equals(new Atom("b"))) {
            System.out.println("failed:");
            System.out.println("\tresult.arg(2): " + result.arg(2));
        // System.exit(1);
        }
        if (result.arg(5) == null || !result.arg(5).equals(new Atom("e"))) {
            System.out.println("failed:");
            System.out.println("\tresult.arg(5): " + result.arg(5));
        // System.exit(1);
        }
    // arg0(6) throws an exception, as I'd expect it to...
    // if ( ((Compound)result).arg( 7 ) != null ){
    // System.out.println( "failed:" );
    // System.out.println( "\t((Compound)result).arg( 7 ): " + ((Compound)result).arg( 7 ) );
    // System.out.println( "\tshould be null" );
    // System.exit( 1 );
    // }
    } catch (PrologException e) {
        System.out.println("failed");
        e.printStackTrace();
    // System.exit(1);
    }
    System.out.println("passed");
}
Also used : Variable(org.jpl7.Variable) Query(org.jpl7.Query) PrologException(org.jpl7.PrologException) Compound(org.jpl7.Compound) Term(org.jpl7.Term) Atom(org.jpl7.Atom)

Example 2 with PrologException

use of org.jpl7.PrologException in project packages-jpl by SWI-Prolog.

the class Query method get1.

private final boolean get1() {
    // close the query;
    if (Prolog.next_solution(qid)) {
        return true;
    } else {
        // if failure was due to throw/1, build exception term and
        // throw it
        term_t exception_term_t = Prolog.exception(qid);
        if (exception_term_t.value != 0L) {
            Term exception_term = Term.getTerm(new HashMap<term_t, Variable>(), exception_term_t);
            close();
            throw new PrologException(exception_term);
        } else {
            close();
            return false;
        }
    }
}
Also used : org.jpl7.fli.term_t(org.jpl7.fli.term_t)

Aggregations

Atom (org.jpl7.Atom)1 Compound (org.jpl7.Compound)1 PrologException (org.jpl7.PrologException)1 Query (org.jpl7.Query)1 Term (org.jpl7.Term)1 Variable (org.jpl7.Variable)1 org.jpl7.fli.term_t (org.jpl7.fli.term_t)1