tuProlog unknown behavior

Go To StackoverFlow.com


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 {
        } catch (InvalidTheoryException ex) {

SolveInfo solution = engine.solve("go.");

if (solution.isSuccess()) {


This Code must returns 'hello world', but instead of that it answer 'go', any ideas about this erratic behavior?

2012-04-03 23:25
by Jose Guzman
@ProfVersaggi, please I need your Help with this - Jose Guzman 2012-04-04 02:39
I was about to write out almost this exact question! : - Joe 2013-09-06 11:14


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() {

        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


2012-04-05 05:58
by Jose Guzman


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.

2012-04-04 08:50
by CapelliC


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.
2012-04-04 06:43
by magus