!TITLE Collecting together solutions !KEY When there are many solutions to a problem, and when all those solutions are required to be collected together, this can be achieved by repeatedly backtracking and gradually building up a list of the solutions. The following evaluable predicate is provided to automate this process. Note, however, that this is the simple version of this predicate and the implementation does not match the sophistication of the equivalent in DEC10 Prolog (ie the logical semantics are incorrect) - if this does not mean much to you then don't worry about it. bagof(X,P,Bag) Bag is a list of all X's such that P. Ie all the instantiations of X produced by backtracking through all possible solutions of P are gathered into the list Bag. Since this list may contain duplicate elements it is known, technically, as a bag; as opposed to a set, say, which would not allow duplicate elements.