1

I'm trying to capture a constraint variable in findall. But on the other end I get independent copies of the variable:

?- X #> 1, findall(X, (true; true), Xs), X #< 100.
Xs = [_A, _B],
X in 2..99,
_B in 2..sup,
_A in 2..sup.

By looking at the code I would expect _A = X and _B = X instead. It seems the findall machinery makes copies of the captured variable.

I can achieve the desired result by iterating over a list, but that doesn't look like an idiomatic Prolog approach:

?- X #> 1, maplist({X}/[_,R]>>(R=X), [_,_], Xs), X #< 100.
Xs = [X, X],
X in 2..99.

Is it possible to achieve the same result with findall/clauses?

vv270
  • 11
  • 1
  • I think that is still an open problem in Prolog; see: https://stackoverflow.com/a/44728942/ – TessellatingHeckler Dec 18 '22 at 07:51
  • I view `findall` and e.g. `bagof` as far *stranger* in Prolog than iterating over a list (which is simple and clear). Here's the code for `bagof`: https://www.swi-prolog.org/pldoc/doc/_SWI_/boot/bags.pl?show=src#bagof/3 – brebs Dec 18 '22 at 11:15

0 Answers0