findall(?term, +body_term, ?list) [ISO]

This predicate assembles a list of solutions of a goal according to a given pattern, findall(Object, Goal, List). The elements in the list are in order of solution.

The difference with bagof/3 is that all the objects are collected regardless of (possibly) different solutions for variables in Goal.

Assume the database contains the user-defined predicates:

see also: ^/2 bagof/3 setof/3 setof_reverse/3

Examples
findall(Child, age(Child, 5), List). List = [ann, tom]
findall(Child, age(Child,Age), List). Child = __1,
Age = __2,
List = [peter, ann, pat, tom]
findall(Child/Age, age(Child, Age), List). List = [peter/7, ann/5, pat/8, tom/5]
findall(Child, Age ^ age(Child, Age), List). List = [peter, ann, pat, tom]
findall(A, legs(A, N), List). List = [bee, horse, dog, tarantula]

 

Exceptions
Third argument is not a list or a variable. a type_error(list, A) exception is thrown, A is replaced by the incorrect third argument
The second argument must not be an empty variable an instantiation_error is thrown
The second argument is not a correct goal a type_error(callable, A) exception is thrown, A is replaced by the incorrect goal

 

 

info@trinc-prolog.com