Reputation: 2319
In order to write a procedure satisfy(P,L) which returns the list L of all terms X such that the unary predicate P(X) succeeds. I have attempted the following:
satisfy(P,L):- findall(X,call(P(X)),L).
Am I on the right track or I have gone completely off?
Upvotes: 0
Views: 646
Reputation: 22585
You can do it using builtin predicate call/2:
satisfy(P, L):- findall(X, call(P, X), L).
Upvotes: 3
Reputation: 2436
Not quite. You're on the right track using findall/3
, but you can't construct a goal to call by simply stating P(X)
. You need to construct the term using =../2
instead.
Upvotes: 2