How to use and inside findall/3 meta predicate

751 views Asked by At

I would like to write this:

paths( Result ) :-
    findall( B, f(B) , Result ).

f( B ) :-
    f1( B ),
    f2( B ).

in just one line. So basically something like:

paths( Result ) :-
    findall( B, f1(B) AND f2(B), Result ).

I don't know how to express 'AND' in a goal statement. Is this possible at all?

1

There are 1 answers

0
twinterer On BEST ANSWER

Just put parentheses around it:

paths(Result) :-
    findall(B, (f1(B),f2(B)), Result).

Addition: Goals are just conjunctions (and disjunctions) of sub-goals. You can construct them at some point, and then pass them around until they are called. This is useful if the goal needs to be constructed dynamically:

Goal = (f1(X), (f2(X) ; f3(X))),
findall(X, Goal, Result),