| McGowan 2007-03-20, 8:08 am |
| Hi, here is my java code and my prolog code. The prolog code works
fine and is tested (it is pretty simple).
child_of(joe, ralf).
child_of(mary, joe).
child_of(steve, joe).
descendent_of(X, Y) :-
child_of(X, Y).
descendent_of(X, Y) :-
child_of(Z, Y),
descendent_of(X, Z).
----------
import java.util.Hashtable;
import jpl.*;
import jpl.Query;
public class Try
{
public static void
main( java.lang.String argv[] )
{
Query q1 = new Query("consult", new Term[] {new Atom("test.pro")});
System.out.println( "consult " + (q1.query() ? "succeeded" :
"failed"));
Variable X = new Variable("_");
Query q4 = new Query("descendent_of",new Term[] {new Atom("mary"),
X});
while ( q4.hasMoreElements() ) {
Hashtable binding = (Hashtable) q4.nextElement();
Term t = (Term) binding.get( X);
System.out.println("X = " + t);
}
}
}
I'm expecting the while loop to return:
consult succeeded
X = joe
X = ralf
except it returns:
consult succeeded
X = null
X = null
Obviously the query is working and returning 2 results so I dont see
why it isn't getting the results correctly?
|