How to find all prolog rules in the database

Suppose I have db facts filled in at least:

fact1(A) :- !, A=ok. fact2(B) :- !, B=ok. 

How can I list all the facts in this db? Ideally, I would have a predicate that I could use:

 ?- all_rules( Head :- Tail). Head=fact1(_G100), Tail=(!, _G100=ok) ; Head=fact2(_G101), Tail=(!, _G101=ok) ....followed by all other predicates in other modules loaded... 

I found current_predicate / 1 , but I cannot figure out what this actually does ...

+7
source share
2 answers

It depends on the exact Prolog system you are using. As long as you want to see the definitions, listing/0 works on many systems. But listing/0 only prints text. clause/2 often only works for dynamically declared predicates.

+7
source

Maybe something like this:

 ?- current_predicate(Name/Arity), functor(Pred, Name, Arity), nth_clause(Pred, Index, Ref), clause(Head, Body, Ref). 

More in the Study program .

+6
source

All Articles