findALL(X,Goal, Xlst):- Goal, %Find a solution assertz(queue(X)), % put it in database fail; % backtrack to find more solutions assertz(queue(bottom)), % mark end collect(Xlst). collect(L):- retract(queue(X)), !, %remove from data base next solution ( X == bottom,!, L=[] % end of solutions? ; L = [X|Rest],collect(Rest) ). % if not collect the rest /* findall(+Template, :Goal, -Bag) [ISO] Create a list of the instantiations Template gets successively on backtracking over Goal and unify the result with Bag. Succeeds with an empty list if Goal has no solutions */ /* retract(+Term) When Term is an atom or a term it is unified with the first unifying findALL(X,Goal, Xlst):- fact or clause in the database. The fact or clause is removed from the database. */ /* page 169 Bratko , */ findallA(X,Goal, _Xlst):- Goal, %Find a solution assertz(queue(X)), % put it in database fail,!. % backtrack to find more solutions findallA(_X,_Goal, Xlst):- assertz(queue(bottom)), % mark end collect(Xlst).