Is it possible to define a list, that consists of predicates and how do I call the predicates.
Also, is it possible to pass one predicate to another predicate (like passing atoms)?
Example:
pre1:- something.
pre2(Predicate1, List):-
call(Predicate1),
append([Predicate1], List, R),
.....
You can't store predicates in a list, but you can store terms (or functors) and call terms as goals.
Here's a predicate that tests whether a term has the properties described by a list of functors:
Usage:
The answer to this query will depend on your definition of
foo/1
, of course. See my explanation of=..
if needed.Edit: as @false reports in the comments, it's not necessary to use
=..
, sinceGoal =.. [P, X], call(Goal)
can be replaced bycall(P, X)
will have the same effect. It might still be worthwhile learning about=..
, though, as you may encounter it in other people's code.