findall(+Template, +Generator, -List)
findall(+Template, +Generator, -List, +Remainder)
List is the list of all the instances of Template for which the goal Generator succeeds, appended to Remainder. Remainder defaults to the empty list.
callable, must be nonvar
A goal to be proved as if by
list of term
list of term
A special case of
bagof/3, where all free variables in the
generator are taken to be existentially quantified, as if by means of
the ‘^’ operator. Contrary to
if there are no instances of Template such that
Generator succeeds, then List = Remainder.
findall/[3,4] avoids the relatively expensive variable
analysis done by
appropriate rather than
bagof/3 can be considerably more
Please note: If the instances being gathered contain
attributed variables (see lib-atts) or suspended goals
(see ref-sem-sec), those variables are replaced by brand new
variables, without attributes, in List. To retain the
attributes, you can use
copy_term/3 (see ref-lte-cpt).
bagof/3 can succeed nondeterminately, generating alternative
values for Set corresponding to different instantiations of the
free variables of Generator.
Call errors (see ref-sem-exc).
To illustrate the differences among
| ?- [user]. | foo(1,2). | foo(1,2). | foo(2,3). | % user compiled in module user, 0.100 sec 352 bytes yes | ?- bagof(X, foo(X,Y), L). Y = 2, L = [1,1] ? ; Y = 3, L =  ? ; no
| ?- bagof(X, Y^foo(X,Y), L). L = [1,1,2] ? ; no
| ?- findall(X, foo(X,Y), L). L = [1,1,2] ? ; no | ?- findall(X, foo(X,Y), L, S). L = [1,1,2|S] ? ; no
| ?- setof(X, foo(X,Y), L). X = _3342, Y = 2, L =  ; X = _3342, Y = 3, L =  ; no
findall/3 is part of the ISO Prolog standard;
findall/4 is not.