Search in sources :

Example 1 with Integer

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

the class FamilyMT method run.

public void run() {
    Map<String, Term> solution;
    // Variable X = new Variable("X");
    // 
    Query q2 = new Query("child_of(joe,ralf)");
    System.err.println("child_of(joe,ralf) is " + (q2.hasSolution() ? "provable" : "not provable"));
    new Query("sleep(?)", new Term[] { new org.jpl7.Integer(delay) }).hasSolution();
    // 
    Query q3 = new Query("descendent_of(steve,ralf)");
    System.err.println("descendent_of(steve,ralf) is " + (q3.hasSolution() ? "provable" : "not provable"));
    delay();
    // 
    Query q4 = new Query("descendent_of(X, ralf)");
    solution = q4.oneSolution();
    System.err.println("first solution of descendent_of(X, ralf)");
    System.err.println("X = " + solution.get("X"));
    delay();
    // 
    Map<String, Term>[] solutions = q4.allSolutions();
    System.err.println("all solutions of descendent_of(X, ralf)");
    for (int i = 0; i < solutions.length; i++) {
        System.err.println("X = " + solutions[i].get("X"));
    }
    delay();
    // 
    System.err.println("each solution of descendent_of(X, ralf)");
    while (q4.hasMoreSolutions()) {
        solution = q4.nextSolution();
        System.err.println("X = " + solution.get("X"));
    }
    delay();
    // 
    Query q5 = new Query("descendent_of(X, Y)");
    System.err.println(id + ": each solution of descendent_of(X, Y)");
    while (q5.hasMoreSolutions()) {
        solution = q5.nextSolution();
        System.err.println(id + ": X = " + solution.get("X") + ", Y = " + solution.get("Y"));
        delay();
    }
}
Also used : Query(org.jpl7.Query) Term(org.jpl7.Term) Map(java.util.Map)

Example 2 with Integer

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

the class TestJUnit method testBigInteger1.

public void testBigInteger1() {
    BigInteger a = new BigInteger(Long.toString(51L));
    // 51**51, too big for a long
    BigInteger b = a.pow(51);
    Term x = Query.oneSolution("X is 51**51").get("X");
    assertTrue("X is an org.jpl7.Integer", x.isInteger());
    // System.out.println("X.bigValue() = " + x.bigValue().toString());
    // System.out.println("b.bigValue() = " + b.toString());
    assertTrue("X is a big integer", x.isBigInteger());
    assertTrue("X's big value is 51**51", x.bigValue().equals(b));
}
Also used : BigInteger(java.math.BigInteger) Term(org.jpl7.Term)

Example 3 with Integer

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

the class TestJUnit method testIntegerFromByte1.

public void testIntegerFromByte1() {
    // -128..127
    byte b = (byte) 127;
    Integer i = new Integer(b);
    assertTrue(i.intValue() == b);
}
Also used : Integer(org.jpl7.Integer) BigInteger(java.math.BigInteger)

Example 4 with Integer

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

the class TestJUnit method testJRef1.

public void testJRef1() {
    int i = 76543;
    Integer I = new Integer(i);
    Query q = new Query("jpl_call(?,intValue,[],I2)", new Term[] { Term.objectToJRef(I) });
    Term I2 = q.oneSolution().get("I2");
    assertTrue(I2.isInteger() && I2.intValue() == i);
}
Also used : Integer(org.jpl7.Integer) BigInteger(java.math.BigInteger) Query(org.jpl7.Query) Term(org.jpl7.Term)

Example 5 with Integer

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

the class TestOLD method test10l.

private static void test10l() {
    Query q5 = new Query(new Compound("length", new Term[] { new Variable("Zs"), new org.jpl7.Integer(5) }));
    Map<String, Term> s5 = q5.oneSolution();
    System.err.println("test10l:");
    System.err.println("  length(Zs,5)");
    System.err.println("  " + Util.toString(s5));
    System.err.println("  Zs = " + (Term) s5.get("Zs"));
    System.err.println();
}
Also used : Integer(org.jpl7.Integer) Variable(org.jpl7.Variable) Query(org.jpl7.Query) Compound(org.jpl7.Compound) Term(org.jpl7.Term)

Aggregations

Integer (org.jpl7.Integer)9 Term (org.jpl7.Term)9 BigInteger (java.math.BigInteger)8 Query (org.jpl7.Query)8 Variable (org.jpl7.Variable)5 Compound (org.jpl7.Compound)4 Map (java.util.Map)3 Atom (org.jpl7.Atom)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