According to help(foreach), there are foreach/3
, and foreach/4
in addition to foreach/2
, with a sample query:
?- phrase(foreach(between(1,5,X), number(X), ", "), L).
My impression is: Are foreach/3
, and foreach/4
necessary ? Their semantics look too procedural compared with foreach/2
. And foreach/2
already can do such a similar job.
comma_list_mem(X, X).
comma_list_mem(X, (X,_)).
comma_list_mem(X, (_,Y)):- comma_list_mem(X, Y).
% ?- foreach((between(1,3,X),number(X)), comma_list_mem(X, L)).
%@ L = (1, 2, 3)
Of course, I do not insist, but just express first sight impression. There must be practical needs.