Find all atom related sentences

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

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

Is there any way to get all the possible information about that (or at least all the facts that are explicitly indicated in the database)? I understand that such a request is not possible:

?- Pred(tom).

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

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

so that I can write queries like

?- meta(tom, Predicate).

but this does not work because the arguments are callnot sufficiently instantiated. So basically my question is: is this possible, or is Prolog not developing this information? And if this is not possible, why?

+3
source share
1

ISO "current_predicate/1", , . :

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

info(Arg,Info) :- current_predicate(PredName/1),
     Info =.. [PredName,Arg], call(Info).
all_info(Arg,L) :- findall(I,info(Arg,I),L).

( SICStus Prolog btw):

| ?- info(tom,X).
X = animal(tom) ? ;
X = cat(tom) ? ;
no
| ?- all_info(tom,X).
X = [animal(tom),cat(tom)] ? 
yes

,

current_predicate
:
| ?- current_predicate(X).
X = info/2 ? ;
X = animal/1 ? ;
X = cat/1 ? ;
X = all_info/2 ? ;
no
+1

Source: https://habr.com/ru/post/1742894/


All Articles