Search in sources :

Example 1 with Atom

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

the class Zahed method main.

public static void main(java.lang.String[] argv) {
    System.out.println("starting...");
    Compound goal1 = new Compound("consult", new Term[] { new Atom("zahed.pl") });
    Query q1 = new Query(goal1);
    if (!q1.hasSolution()) {
        System.out.println("consult('zahed.pl') failed");
        return;
    }
    Term t2 = new Compound("t", new Term[] { new Atom("v"), new Atom("[]"), new Atom("a") });
    Compound list2 = new Compound(".", new Term[] { t2, new Atom("[]") });
    Compound t1 = new Compound("t", new Term[] { new Atom("c"), new Atom("q"), new Atom("[]") });
    Compound list1 = new Compound(".", new Term[] { t1, list2 });
    Variable answer = new Variable("A");
    Compound goal2 = new Compound("gen", new Term[] { list1, answer });
    Query q2 = new Query(goal2);
    Map<String, Term> solution = q2.oneSolution();
    if (solution == null) {
        System.out.println("failed");
    } else {
        System.out.println(solution.get("A").toString());
    }
    System.out.println("finished");
}
Also used : Variable(org.jpl7.Variable) Query(org.jpl7.Query) Compound(org.jpl7.Compound) Term(org.jpl7.Term) Atom(org.jpl7.Atom)

Example 2 with Atom

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

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

the class TestJUnit method testAtomEquality1.

public void testAtomEquality1() {
    String name = "fred";
    Atom a1 = new Atom(name);
    Atom a2 = new Atom(name);
    assertEquals("two Atoms created with the same name are equal", a1, a2);
}
Also used : Atom(org.jpl7.Atom)

Example 4 with Atom

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

the class TestJUnit method testAtomToString2.

public void testAtomToString2() {
    String name = "ha ha";
    String toString = "'ha ha'";
    Atom a = new Atom(name);
    assertEquals("an Atom's .toString() value is quoted iff appropriate", a.toString(), toString);
}
Also used : Atom(org.jpl7.Atom)

Example 5 with Atom

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

the class TestJUnit method testAtomArity.

public void testAtomArity() {
    Atom a = new Atom("willy");
    assertEquals("an Atom has arity zero", a.arity(), 0);
}
Also used : 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