Find all clauses related to an atom

Posted by Luc Touraille on Stack Overflow See other posts from Stack Overflow or by Luc Touraille
Published on 2010-04-26T22:56:48Z Indexed on 2010/04/27 7:03 UTC
Read the original article Hit count: 276

Filed under:

This is probably a very silly question (I just started learning Prolog a few hours ago), but is it possible to find all the clauses related to an atom? For example, assuming the following knowledge base:

cat(tom).
animal(X) :- cat(X).

, is there a way to obtain every possible information about tom (or at least all the facts that are explicitly stated in the base)? I understand that a query like this is not possible:

?- Pred(tom).

so I thought I could write a rule that would deduce the correct information:

meta(Object, Predicate) :-
    Goal =.. [Predicate, Object],
    call(Goal).

so that I could write queries such as

?- meta(tom, Predicate).

but this does not work because arguments to call are not sufficiently instantiated. So basically my question is: is this at all possible, or is Prolog not design to provide this kind of information? And if it is not possible, why?

© Stack Overflow or respective owner

Related posts about prolog