Let's assume I have something like:
% person(ID, Name, Age)
person(_, paul, Age).
person(_, Name, 20).
...
...and instead of the typical binding I would like to have a helper function get_person_list(ID, Name, Age)
that calls person
but returns me a list:
?- get_person_list(_, Name, 20).
[frank, jack, jane].
...to get a list for e.g. all persons with age 20. How can I achieve this?
In your code, you don't provide a parameter for the resulting list.
Just call:
You can make a separate predicate for this query if you really need it often, of course.
See also
bagof/3
, as explained in Boris's answer.