Preserve clpfd constraint variable in findall

92 views Asked by At

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?

0

There are 0 answers