For Programmers: Free Programming Magazines  


Home > Archive > Prolog > April 2007 > SWI-Prolog query returning null values.









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author SWI-Prolog query returning null values.
McGowan

2007-03-20, 8:08 am

Hi, here is my java code and my prolog code. The prolog code works
fine and is tested (it is pretty simple).

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).

----------

import java.util.Hashtable;
import jpl.*;
import jpl.Query;

public class Try
{
public static void
main( java.lang.String argv[] )
{

Query q1 = new Query("consult", new Term[] {new Atom("test.pro")});

System.out.println( "consult " + (q1.query() ? "succeeded" :
"failed"));


Variable X = new Variable("_");

Query q4 = new Query("descendent_of",new Term[] {new Atom("mary"),
X});

while ( q4.hasMoreElements() ) {
Hashtable binding = (Hashtable) q4.nextElement();
Term t = (Term) binding.get( X);
System.out.println("X = " + t);
}
}
}

I'm expecting the while loop to return:

consult succeeded
X = joe
X = ralf

except it returns:

consult succeeded
X = null
X = null

Obviously the query is working and returning 2 results so I dont see
why it isn't getting the results correctly?

Superstar

2007-04-01, 12:39 am

Catherine Zeta Jone Throatjob!
http://Catherine-Zeta-Jone-Throatjo...hp?movie=148803
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com