As far as I understand the predicates setof/3 and bagof/3 can be used generate a list of solutions to a problem. (Link to gprolog manual).
As expected the solutions to the following query are a, b and c.
?- nth(_, [a,b,c], X).
X = a ? ;
X = b ? ;
X = c ? ;
yes
And now I try this:
?- setof(X, nth(_, [a,b,c], X), ListOfSolutions).
ListOfSolutions = [a] ? ;
ListOfSolutions = [b] ? ;
ListOfSolutions = [c]
yes
The solution should have been [a,b,c] in my opinion. What am I doing wrong?
I am using gprolog 1.4.0 for Mac OS.
Edit: Solution
What I really needed was the (^)/2 operator, but the answer given here was completely correct, thank you very much for your help. If anyone has a similar problem here is my current code to select cells from a 3-dimensional grid.
% selectFLR(?Grid, ?ClassId, ?TDayIdD, ?HourId, -ListOfFLR)
% ---------------------------------------------------------
selectFLR(Grid, ClassId, DayId, HourId, ListOfFLR) :-
bagof(FLR, ClassId^DayId^HourId^selectSingleFLR(Grid, ClassId, DayId, HourId, FLR), ListOfFLR).
selectSingleFLR(Grid, ClassId, DayId, HourId, FLR) :-
nth(ClassId, Grid, Class),
nth(DayId, Class, Day),
nth(HourId, Day, FLR).