Error cases are the same as predicate call/1 (see Section 6.10).
Example: Consider the following predicate:
p(red,high,1).
p(green,low,2).
p(blue,high,3).
p(black,low,4).
p(black,high,5).
The goal ?- setof(Color,Height^Val^p(Color,Height,Val),List)
returns a single solution:
Color = _h73
Height = _h87
Val = _h101
L = [black,blue,green,red]
If Height is removed from the sequence of existential variables, so
that the goal becomes:
?- setof(Color,Val^p(Color,Height,Val),List)}, the first solution is:
Color = _h73
Val = _h87
Height = high
L = [black,blue,red];
upon backtracking, a second solution is produced:
Color = _h73
Val = _h87
Height = low
L = [black,green]
Error Cases are the same as predicate call/1 (see Section 6.10).
Example:
For the predicate p/3 in the example for setof/3, the
goal
?- bagof(Color,Height^Val^p(Color,Height,Val),L) returns
the single solution:
Color = _h73
Height = _h87
Val = _h101
L = [red,green,blue,black,black];
If Height is removed from the sequence of existential variables, so
that the goal becomes:
?- bagof(Color,Val^p(Color,Height,Val),List), the first solution is:
Color = _h73
Val = _h87
Height = high
L = [red,blue,black];
upon backtracking, a second solution is produced:
Color = _h73
Val = _h87
Height = low
L = [green,black];
Error cases are the same as call/1 (see Section 6.10).
Example:
For the predicate p/3 in the example for setof/3, the goal
findall(Color,p(Color,Height,Val),L) returns a single solution:
Color = _h73
Height = _h107
Val = _h121
F = [red,green,blue,black,black]
Note: tfindall/3 may be deprecated in current versions. Please use the predicates described in Section 6.9.1 if possible.
Like findall/3, tfindall/3 treats all variables in Goal that do not occur in Template as existential. However, in tfindall/3, the Goal must be a call to a single tabled predicate.
tfindall/3 allows the user to build programs that use stratified aggregation. If the table to Goal is incomplete, tfindall/3 suspends until the table has been completed, and only then computes List. See Chapter 5 for further discussion of tfindall/3. Like findall/3, if Goal is unsatisfiable, tfindall/3 succeeds binding List to the empty list.
Some of the differences between predicates findall/3 and tfindall/3 can be seen from the following example:
| ?- [user].
[Compiling user]
:- table p/1.
p(a).
p(b).
[user compiled, cpu time used: 0.639 seconds]
[user loaded]
yes
| ?- p(X), findall(Y, p(Y), L).
X = a
Y = _922928
L = [a];
X = b
Y = _922820
L = [a,b];
no
| ?- abolish_all_tables.
yes
| ?- p(X), tfindall(Y, p(Y), L).
X = b
Y = _922820
L = [b,a];
X = a
Y = _922820
L = [b,a];
no
Error cases are the same as predicate findall/3 (see above). Also:
Note: tbagof/3 and tsetof/3 may be deprecated in current versions. Please use the predicates described in Section 6.9.1 if possible.
The standard predicates tbagof/3 and tsetof/3 provide tabled versions of bagof/3 and setof/3 in a similar manner to the way in which tfindall/3 provides a tabled version of findall/3.