Question

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?

Was it helpful?

Solution

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),
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top