If I have a list of predicates in Prolog like [flies, swims]
, how can I build a predicate that is the conjunction of all the predicates in the list, ie fliesAndSwims(X) :- flies(X), swims(X).
?
Alternatively, is there a better way of building up a predicate at runtime like this without putting the component predicates in a list and building the compound one from them when needed?
EDIT: So it turns out this is a duplicate of List of predicates in Prolog. I had previously found that answer, but I thought that it only returned whether a given atom matched every predicate in the list. I didn't realise that you can pass a variable instead of an atom and have it return every case that matches as well.