Search in sources :

Example 16 with Compound

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

the class TestJUnit method testRef6.

public void testRef6() {
    Term nullJRef = new Compound("@", new Term[] { new Atom("null") });
    Object nullObject = nullJRef.jrefToObject();
    assertNull("@(null) .jrefToObject() yields null", nullObject);
}
Also used : Compound(org.jpl7.Compound) Term(org.jpl7.Term) Atom(org.jpl7.Atom)

Example 17 with Compound

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

the class TestJUnit method testVariableBinding5.

public void testVariableBinding5() {
    Variable Anon = new Variable("_");
    Term lhs = new Compound("p", new Term[] { Anon, Anon });
    Term rhs = new Compound("p", new Term[] { new Atom("a"), new Atom("b") });
    Term goal = new Compound("=", new Term[] { lhs, rhs });
    assertTrue("two references to an anonymous Variable can unify with differing atoms", new Query(goal).hasSolution());
}
Also used : Variable(org.jpl7.Variable) Query(org.jpl7.Query) Compound(org.jpl7.Compound) Term(org.jpl7.Term) Atom(org.jpl7.Atom)

Example 18 with Compound

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

the class TestJUnit method testVariableBinding4.

public void testVariableBinding4() {
    Term lhs = new Compound("p", new Term[] { new Variable("_"), new Variable("_") });
    Term rhs = new Compound("p", new Term[] { new Atom("a"), new Atom("b") });
    Term goal = new Compound("=", new Term[] { lhs, rhs });
    assertTrue("two distinct anonymous Variables can unify with distinct atoms", new Query(goal).hasSolution());
}
Also used : Variable(org.jpl7.Variable) Query(org.jpl7.Query) Compound(org.jpl7.Compound) Term(org.jpl7.Term) Atom(org.jpl7.Atom)

Example 19 with Compound

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

the class TestJUnit method testLength1.

public void testLength1() {
    Query q5 = new Query(new Compound("length", new Term[] { new Variable("Zs"), new org.jpl7.Integer(2) }));
    Term zs = q5.oneSolution().get("Zs");
    assertTrue("length(Zs,2) binds Zs to a list of two distinct variables " + zs.toString(), zs.isListPair() && zs.arg(1).isVariable() && zs.arg(2).isListPair() && zs.arg(2).arg(1).isVariable() && zs.arg(2).arg(2).isListNil() && !zs.arg(1).name().equals(zs.arg(2).arg(1).name()));
}
Also used : Integer(org.jpl7.Integer) BigInteger(java.math.BigInteger) Variable(org.jpl7.Variable) Query(org.jpl7.Query) Compound(org.jpl7.Compound) Term(org.jpl7.Term)

Example 20 with Compound

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

the class TestJUnit method testVariableBinding2.

public void testVariableBinding2() {
    Term lhs = new Compound("p", new Term[] { new Variable("X"), new Variable("X") });
    Term rhs = new Compound("p", new Term[] { new Atom("a"), new Atom("b") });
    Term goal = new Compound("=", new Term[] { lhs, rhs });
    assertFalse("two distinct Variables with same name cannot unify with distinct atoms", new Query(goal).hasSolution());
}
Also used : Variable(org.jpl7.Variable) Query(org.jpl7.Query) Compound(org.jpl7.Compound) Term(org.jpl7.Term) Atom(org.jpl7.Atom)

Aggregations

Compound (org.jpl7.Compound)21 Term (org.jpl7.Term)21 Variable (org.jpl7.Variable)17 Query (org.jpl7.Query)16 Atom (org.jpl7.Atom)13 Map (java.util.Map)4 Integer (org.jpl7.Integer)4 BigInteger (java.math.BigInteger)3 PrologException (org.jpl7.PrologException)2 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