I'm using tuProlog to integrate Prolog with Java, to do so I'v been defined a .pl file wich contains this code:
go:-write('hello world!'),nl.
In my Java File at NetBeans i Have a Main Class that invokes this:
Prolog engine = new Prolog();
Theory theory = new Theory(new FileInputStream("facultad.pl"));
try {
engine.setTheory(theory);
} catch (InvalidTheoryException ex) {
}
SolveInfo solution = engine.solve("go.");
if (solution.isSuccess()) {
System.out.println(solution.getSolution());
}
This Code must returns 'hello world', but instead of that it answer 'go', any ideas about this erratic behavior?
Finally i found that this behavior is not erratic.
The solution is to add this code just before call the Solve Method.
engine.addOutputListener(new OutputListener() {
@Override
public void onOutput(OutputEvent e) {
finalResult += e.getMsg();
}
});
finalResult it's a Global variable which contains the returned String produced by Prolog Write instruction.
That's all I've n made a class if any needs their implementation just write me a mail jrguzman(at)estudiantes(dot)uci(dot)cu
Regards.
Your solution it's (correctly) the succeded Prolog query (go/0), what you expect ('hello world!') it's the output of a builtin, as such you should inspect the 'stdout' of your Java engine.
Otherwise, code your program to 'return' info in variables.
go(X) :- X = 'hello world!'.
Then tuProlog will provide the methods to access instanced variables.
I don't know about tuProlog/Java, but when calling Swi-Prolog from PHP, I must put 'halt' as the final statement of the predicate to tell Prolog to exit and return control back to php.
go:-write('hello world!'),nl, halt.