[det]foldall(:Folder,
:Goal, +V0, -V)Use Folder to fold V0 to V using all
answers of Goal. This predicate generates all answers for Goal
and for each answer it calls
call(Folder,V0,V1)
. This predicate provides behaviour
similar to
aggregate_all/3-4,
but operates in constant space and allows for custom aggregation (Folder)
operators. The example below uses plus/3
to realise aggregate_all(sum(X), between(1,10,X), Sum)
.
?- foldall(plus(X), between(1,10,X), 0, Sum).
Sum = 55
The implementation uses nb_setarg/3
for non-backtrackable state updates.
- See also
- aggregate_all/3-4, foldl/4-7, nb_setarg/3.