import java.util.Hashtable;
import jpl.*;
import jpl.Query;
public class Family {
public static void main( String argv[] ) {
String t1 = "consult('C:/Users/Kostas/Desktop/family.pl')";
Query q1 = new Query(t1);
System.out.println( t1 + " " + (q1.hasSolution() ? "succeeded" : "failed"));
//---
String t2 = "child_of(joe, ralf)";
Query q2 = new Query(t2);
System.out.println(q2.hasSolution());
//---
String t3 = "descendent_of(X, ralf)";
Query q3 = new Query(t3);
java.util.Hashtable[] s3 = q3.allSolutions();
System.out.println("all solutions of " + t3);
for (int i = 0; i < s3.length; i++) {
System.out.println("X = " + s3[i].get("X"));
}
}
}
Output:
consult('C:/Users/Kostas/Desktop/family.pl') succeeded
true
all solutions of descendent_of(X, ralf)
X = null
X = null
X = null
% family.pl
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).
Hello,
I run the above code on Eclipse. Generally it's ok, except when i use variables. In the above case it should print out:
X = joe
X = mary
X = steve
Instead it prints 'X = null'.
Same question has been asked before here: https://stackoverflow.com/questions/30495077/swi-prolog-returns-null-but-hassolutions-true-and-also-allsolutions-is-true
The guy that asked the question said that this was due to the jpl.jar file. if that's the problem, where can i find the appropriate version of jpl.jar in order to solve my problem? Note that recently i downloaded the latest version of SWI-Prolog which probably includes the latest version of jpl.jar library file as well. This is the version that i use.
Thanks.