views:

59

answers:

1

Hello,

I was wondering whether anyone had managed to use the 'listing.' command in JPL to examine the contents of the Prolog knowledgebase? JPL requires you construct queries and will return solutions based on the variables which you set in the query. For example (Java):

Query q = new Query("holdsAt((X,Y) = true, 3)");
while ( q.hasMoreSolutions() ){
 Hashtable s = q.nextSolution();
 System.out.println(s.get("X")+", "+s.get("Y"));
}

I can't see how this would work for listing/0, or even listing/1 which requires an instantiated input. At the moment I am playing around with code of the form

predicate_property(L,interpreted), 
\+ predicate_property(L, built_in), 
\+ predicate_property(L,imported_from(_)), 
current_predicate( X, L), current_predicate(X/Z).

which returns for a function existing in the knowledgebase:

myFunction:-
 myGoal1,
 myGoal2.

the answer:

L = myFunction(_G403,_G404),
X = myFunction,
Z = 2

But it's not sufficient as none of the goals are returned. I suppose what I require (if the listing function cannot be called using JPL), is a function which returns as a variable the predicate head along with a list of the relevant goals which must be satisfied. Unfortunately, I'm not familiar with the internals of the listing function, so I'm not sure how to go about doing this.

Thanks in advance

A: 

I have a function which is working for the time being, but I am concerned that it is less efficient than a 'listing' call

getClauses(Y):-
 predicate_property(L,interpreted), 
 \+ predicate_property(L, built_in), 
 \+ predicate_property(L,imported_from(_)), 
 current_predicate( X, L), 
 current_predicate(X/Z),
 findall((L, T), clause(L, T), Y).

which returns for a predicate existing in the knowledgebase:

myPredicate:-
 myGoal1,
 myGoal2.

the result:

?- getClauses(Y).
Y = [ (myPredicate, myGoal1, myGoal2)]

Note that this will not work for predicates which have been imported from other modules.

Huguenot
Follow up: It turns out the findall is excessive.
Huguenot