hector
YaBB Newbies
Offline
Posts: 25
Re: java-prolog problem
Reply #1 - Feb 26th , 2008, 5:07am
And here is my response to my own question. I have been struggling with this for days, and right after I decide to post, the solution strikes me.... It is really, really, really simple. Many apologies for wasting everybody's time, but here is the correct code. I have added comments to indicate the changes that made all the difference.... This might help people out, in case they want to try to do what I have done, since the online SWI-Prolog doc is wrong (!!!!). <code begins> import jpl.fli.*; import jpl.*; Atom x = new Atom("test.pl" ); Term arg[] = { x } ; Query q1 = new Query( "consult", arg ); println(q1); println( "consult " + (q1.query() )); Query q2 = new Query( "child_of", new Term[] {new Atom("joe"),new Atom("ralf")} ); println( "child_of(joe,ralf) is " + ( q2.query() ? "provable" : "not provable" ) ); //The problem is the next statement. The code in the SWI web site is: // ....new Variable(X). //This is wrong: use double quotes instead! Variable X = new Variable("X"); Query q4 = new Query( "child_of", new Term[] {new Atom("joe"), X} ); println(q4); Hashtable solution; solution = q4.oneSolution(); //again: use solution.get("X") --include the double quotes! println( "X = " + solution.get("X")); java.util.Hashtable[] solutions = q4.allSolutions(); for ( int i=0 ; i<solutions.length ; i++ ) { //again, use get("X")... println( "X = " + solutions[i].get("X")); } <code ends> If anybody wants to know all of the steps needed to make jpl into a library for prolog, I am happy to post them (as far as I can remember what I have done...)