Hello,
I'm using Ciao-1.7p30 on a Windows NT sp5 machine.
I'm trying to determine how, using the Java interfaces, to tell the prolog server to do an assert.
I have tried constructing a goal G containing asserta(foo(5)) followed by a call to G.query(). A subsequent call to G.nextSolution() will simply hang in a read, and a G.terminate() call generates a PLException: Termination has not been accepted by the server.
(Using a goal doesn't really seem correct to do an assert, but I see no other class that might be appropriate).
I can successfully run the queens example (using both the Javasoft JDK and the Microsoft VM) in the library\ javall\Examples\java2pl directory, both as distributed and integrated into my program -- so I believe my general usage is alright.
The relevant section of java code I'm using is appended to the end of this message (as well as a mod to PLConnection).
Any help is appreciated!
-- Dan larner(a)parc.xerox.com
--------------------------------------------
PLTerm solution; // build up foo(5). String fooFunctor = "foo"; PLTerm[] fooArgs = new PLTerm[1]; fooArgs[0] = new PLInteger(5); PLStructure foo = new PLStructure(fooFunctor, fooArgs);
// build up asserta(foo(5)). String assertaFunctor = "asserta"; PLTerm[] assertaArgs = new PLTerm[1]; assertaArgs[0] = foo; PLStructure assertFoo = new PLStructure(assertaFunctor, assertaArgs);
// create a goal holding the asserta(foo(5)). currentGoal = new PLGoal(sm_plServer, assertFoo);
// tell prolog asserta(foo(5)). System.out.println("Doing " + currentGoal); currentGoal.query(); // trying currentGoal.terminate(); at this point // generates PLException: Termination has not // been accepted by the server // trying solution = currentGoal.nextSolution(); at // this point just hangs in a read
--------------------------------------------
I found that when running with the Microsoft VM, I needed to add a close method to PLConnection, and call it before exit in order to have the prolog process terminate. Here's the method for anyone interested:
/** closes the connection - it's no longer usable */ public void close() { try { plIn.close(); } catch (Exception e) { System.err.println("PLConnection: Problem closing plIn " + e); } try { evIn.close(); } catch (Exception e) { System.err.println("PLConnection: Problem closing plIn " + e); } plOut.close(); evOut.close(); }