This is a simple question (I think) but I can’t find a good solution:
I want a predicate that captures the result of the first N backtracks of a goal or a closure (as opposed to all the backtracks as done by setof/3 and bagof/3):
capture(N, Template, Goal, Bag) :- …
for example, capturing 3 backtracks of length/2 called as length(L,LL) into a Bag using template [ L,LL ] would give [ [[],0], [[_7180],1], [[_10020, _11052],2] ]
(… and there seem to be “Cookbook” books for all sorts of Languages, demonstrating standard tricks, but there isn’t for Prolog. Or is there?)
Nice solutions. I was about to think about starting a Prolog engine to get at this.
A remark has been added to the SWI-Prolog manual page of between/3, which is, a bit awkwardly, classed under “special purpose integer arithmetic”, although (at least for me) the poodle’s kernel of it is really “control predicate”.