There is a broken link on this page. I hope it will be updated soon.
:- use_module(library(aggregate)).(can be autoloaded)
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.
You want a nice example of foreach? Here you are the most declarative permutation generator on Earth...