If I had two predicates that generate values in a sequence, for example:
between(1, 3, X), sub_atom(abc, _, 1, _, Y)
How can I iterate through them so that I get the solutions:
X = 1, Y = a ;
X = 2, Y = b ;
X = 3, Y = c.
Trying the normal way of course doesn't work:
?- between(1, 3, X), sub_atom(abc, _, 1, _, Y).
X = 1, Y = a ;
X = 1, Y = b ;
X = 1, Y = c ;
X = 2, Y = a ;
Of course I can collect the two in lists separately:
?- findall(X, between(1, 3, X), Xs), findall(Y, sub_atom(abc, _, 1, _, Y), Ys).
Xs = [1, 2, 3],
Ys = [a, b, c].
but this is what I want to avoid. I don't want to make the full list, maybe it is too big. Or maybe I want to use something like between(1, inf, X) as one of the generators.
There seems to be a solution for something similar called merge and outlined here: https://www.swi-prolog.org/pldoc/man?section=engine-examples but it does something different.