Search in sources :

Example 16 with Atom

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

the class TestJUnit method testEmptyParentheses.

// the tests; all public void test*()
// public void testInfo() {
// Term swi = Query.oneSolution("current_prolog_flag(version_data,Swi)").get("Swi");
// System.out.println("version = " + swi.arg(1) + "." + swi.arg(2) + "." + swi.arg(3));
// System.out.println("syntax = " + Query.oneSolution("jpl:jpl_pl_syntax(Syntax)").get("Syntax"));
// System.out.println("jpl.jar = " + JPL.version_string() + " " + JPL.jarPath());
// System.out.println("jpl.dll = " + Prolog.get_c_lib_version());
// System.out.println("jpl.pl = " + Query.oneSolution("jpl:jpl_pl_lib_version(V)").get("V").name() + " "
// + Query.oneSolution("module_property(jpl, file(F))").get("F").name());
// System.out.println("home = " + Query.oneSolution("current_prolog_flag(home,Home)").get("Home").name());
// }
public void testEmptyParentheses() {
    // valid in both
    Term t = Query.oneSolution("T = a()").get("T");
    // traditional and
    // modern syntax in SWI
    // Prolog 7.x
    assertTrue("T is not bound to an atom", t.isAtom());
    assertTrue("the atom's name is not \"a\"", t.name().equals("a"));
}
Also used : Term(org.jpl7.Term)

Example 17 with Atom

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

the class TestJUnit method testJRef5.

public void testJRef5() {
    String token = "foobar345";
    Term a = Query.oneSolution("jpl_new('java.lang.StringBuffer',[?],A)", new Term[] { new Atom(token) }).get("A");
    assertTrue(((java.lang.StringBuffer) (a.jrefToObject())).toString().equals(token));
}
Also used : Term(org.jpl7.Term) Atom(org.jpl7.Atom)

Example 18 with Atom

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

the class TestJUnit method testOpenGetClose1.

public void testOpenGetClose1() {
    StringBuffer sb = new StringBuffer();
    Query q = new Query("atom_chars(prolog, Cs), member(C, Cs)");
    Map<String, Term> soln;
    q.open();
    while ((soln = q.getSolution()) != null) {
        sb.append(((Atom) soln.get("C")).name());
    }
    q.close();
    assertEquals("prolog", sb.toString());
}
Also used : Query(org.jpl7.Query) Term(org.jpl7.Term)

Example 19 with Atom

use of org.jpl7.Atom 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 20 with Atom

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

the class TestGC method main.

public static void main(String[] argv) {
    int max;
    Query.hasSolution("consult('test.pl')");
    if (argv.length > 0)
        max = Integer.parseInt(argv[0]);
    else
        max = 10;
    System.out.println(max + " iterations");
    for (int i = 0; i < max; i++) {
        Query q = new Query("testpred", new Term[] { new Atom("a" + i) });
        q.oneSolution();
    }
    Query.hasSolution("stats");
}
Also used : Query(org.jpl7.Query) Atom(org.jpl7.Atom)

Aggregations

Atom (org.jpl7.Atom)32 Term (org.jpl7.Term)23 Query (org.jpl7.Query)19 Compound (org.jpl7.Compound)13 Variable (org.jpl7.Variable)12 Map (java.util.Map)2 PrologException (org.jpl7.PrologException)2 BigInteger (java.math.BigInteger)1 URL (java.net.URL)1 TestSuite (junit.framework.TestSuite)1 JPLException (org.jpl7.JPLException)1 DoubleHolder (org.jpl7.fli.DoubleHolder)1 Int64Holder (org.jpl7.fli.Int64Holder)1 IntHolder (org.jpl7.fli.IntHolder)1 ObjectHolder (org.jpl7.fli.ObjectHolder)1 StringHolder (org.jpl7.fli.StringHolder)1 org.jpl7.fli.term_t (org.jpl7.fli.term_t)1