Last active
July 23, 2018 15:47
-
-
Save tomasklapka/b66f937f4b84a43e22072c26af38c8c9 to your computer and use it in GitHub Desktop.
List all fact predicates for a provided argument
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%%% list all fact Predicates having an Argument as any argument. | |
argument_predicates(Argument, Predicates) :- | |
findall(Predicate, ( | |
predicate_property(M:Clause, file(_)), % list all predicates | |
\+ M = system, % exclude 'system' Module, or you can constrain it to M = user | |
clause(Clause, true), % is Clause a fact?, ie. Body = true. | |
arg(_, Clause, Argument), % Clause has the Argument as an argument (change _ to 1 if Argument has to be the first argument of a predicate). | |
current_predicate(Predicate, Clause), % extract Predicate from Clause (another way: functor(Clause,Predicate,_)) | |
\+ Predicate = ignore % exclude 'ignore' predicate since it succeeds for anything. | |
), Predicates). | |
upper_letter(0'A). | |
upper_letter(0'B). | |
upper_letter(0'C). | |
lower_letter(0'a). | |
lower_letter(0'b). | |
lower_letter(0'c). | |
% ?- argument_predicates(0'A, P). | |
% P = [upper_letter]. | |
% | |
% ?- argument_predicates(0'a, P). | |
% P = [lower_letter]. | |
% | |
my(b). | |
my(a). | |
another(a). | |
andAnother(a,b). | |
my2(c). | |
test(X) :- my(X). | |
my3(c,b,a). | |
% ?- argument_predicates(a, P). | |
% P = [andAnother, another, my, my3] | |
% | |
% ?- argument_predicates(b, P). | |
% P = [andAnother, my, my3]. | |
% | |
% ?- argument_predicates(c, P). | |
% P = [my3, my2]. | |
% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment