Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %%% 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].
- %
Add Comment
Please, Sign In to add comment