A.1 library(aggregate): Aggregation operators on backtrackable predicates
All Application Manual Name SummaryHelp

  • Documentation
    • Reference manual
      • The SWI-Prolog library
        • library(aggregate): Aggregation operators on backtrackable predicates
          • aggregate/3
          • aggregate/4
          • aggregate_all/3
          • aggregate_all/4
          • foldall/4
          • foreach/2
          • free_variables/4
          • safe_meta/2
    • Packages
Availability::- use_module(library(aggregate)).(can be autoloaded)
Source[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.