You can have things in the “database”, for example defined as facts or as multiple solutions for a rule. Those are generated one after the other upon backtracking. So for example, you can have a table of facts:
This will have three solutions, if you query:
X = 1 ;
X = 2 ;
X = 3.
You can also get the same without explicitly defining a table of facts:
?- between(1, 3, X).
X = 1 ;
X = 2 ;
X = 3.
Those two are the same as to how you get your “things” out of it: by backtracking.
Then, you can have a list of things, as in:
[1, 2, 3]. This is now a compound term, a data structure.
(I am getting to it, don’t give up).
There are ways to move the things between the two representations. If you want to go from a simple data structure as the list to a sequence of solutions upon backtracking, you use member/2, like this:
?- member(X, [1, 2, 3]).
To go from solutions to a list, you use findall/3 or bagof/3 (or setof/3):
?- bagof(X, a(X), L).
I am guessing that @peter.ludemann was trying to say that there is no need to switch between the two representations in your case. In particular, this is a severe code smell:
?- findall(X, member(X, List), Xs).
(It can be bagof/3 or setof/3 instead of findall/3)
There might be valid reasons to do this, but this in most cases, you are just doing busywork without achieving anything of value. As a matter of fact:
setof(X, member(X, List), Xs).
is the same as:
findall(X, member(X, List), Xs0), sort(Xs0, X)
And if you have this:
setof(X, ( member(X, List), foo(X) ), Xs)
then this is going to give you the same result in less memory and almost certainly faster:
include(foo, List, Xs0), sort(Xs0, Xs)
sort(List, Xs0), include(foo, Xs0, Xs)
PS: something to keep in mind. First, it is perfectly fine to use findall/3 and bagof/3 and setof/3 when you need them. I will not go into the gory detail of when you need them and how to use them correctly, this post was not supposed to be an article Then, it is perfectly fine to use them as in the “severe code smell” example I gave above, especially if you know that you are dealing with a known, limited number of things. And finally, you will see online quite a bit of one-liners that use findall and bagof and setof like this. Again, this is fine. It becomes problematic when you have a lot of things, at that point your code will become slow, you will be running out of memory and so on.