findall/3findall(+Template, +*Generator, -List)
Collects in List all the instances of Template for
which the goal Generator succeeds. A special case of
bagof/3, where all free variables in the generator are taken to
be existentially quantified.
call/1.
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.
Because findall/3 avoids the relatively expensive variable
analysis done by bagof/3, using findall/3 where appropriate rather
than bagof/3 can be considerably more efficient.
To illustrate the differences among
findall/3, setof/3, and bagof/3:
| ?- [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).
X = _3342,
Y = 2,
L = [1,1] ;
X = _3342,
Y = 3,
L = [2] ;
no
| ?- bagof(X, Y^foo(X,Y), L).
X = _3342,
Y = _3361,
L = [1,1,2] ;
no
| ?- findall(X, foo(X,Y), L).
X = _3342,
Y = _3384,
L = [1,1,2] ;
no
| ?- setof(X, foo(X,Y), L).
X = _3342,
Y = 2,
L = [1] ;
X = _3342,
Y = 3,
L = [2] ;
no
As for call/1.
setof/3, bagof/3, ^/2
ref-all