Suppose I have a facts db filled with at least:
fact1(A) :- !, A=ok.
fact2(B) :- !, B=ok.
How can I enumerate through all the facts in this db? Ideally I'd 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 can't figure out what this is actually doing...
It depends on the precise Prolog system you are using. As long, as you only want to look at the definitions, listing/0
works in many systems. But listing/0
only prints a text. clause/2
often works only for predicates declared dynamically.
Maybe something like this:
?- current_predicate(Name/Arity),
functor(Pred, Name, Arity),
nth_clause(Pred, Index, Ref),
clause(Head, Body, Ref).
Read more in Examining the program.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With