A.1 library(aggregate): Aggregation operators on backtrackable predicates
AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
      • The SWI-Prolog library
        • library(aggregate): Aggregation operators on backtrackable predicates
          • aggregate/3
          • aggregate/4
          • aggregate_all/3
          • aggregate_all/4
          • foreach/2
          • free_variables/4
    • Packages
Availability::- use_module(library(aggregate)).(can be autoloaded)
Sourceforeach(:Generator, :Goal)
True if conjunction of results is true. Unlike forall/2, which runs a failure-driven loop that proves Goal for each solution of Generator, foreach/2 creates a conjunction. Each member of the conjunction is a copy of Goal, where the variables it shares with Generator are filled with the values from the corresponding solution.

The implementation executes forall/2 if Goal does not contain any variables that are not shared with Generator.

Here is an example:

?- foreach(between(1,4,X), dif(X,Y)), Y = 5.
Y = 5.
?- foreach(between(1,4,X), dif(X,Y)), Y = 3.
false.
bug
Goal is copied repeatedly, which may cause problems if attributed variables are involved.