tuProlog unknown behavior

Go To StackoverFlow.com

2

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?

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


1

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.

2012-04-05 05:58
by Jose Guzman


1

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


0

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
Ads