The following code runs in SWI-Prolog:
?-foreach(member(X ,["1","2","3"]) ,(number_codes(Y,X),writeln(Y))).
1
false.
?- foreach(member(X ,["1","2","3"]) ,writeln(X)).
[49]
[50]
[51]
foreach/2 is more complex that forall, and you hit the case where the used variable quantification makes a difference. Try instead
?- forall(member(X, ["1","2","3"]), (number_codes(Y,X), writeln(Y))).
1
2
3
true.
It seems that foreach/2 retains the bindings for Y.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With