PLOGHELP BAGOF Jonathan Laventhol, Thursday 22nd March 1984 Revised by Kathryn Seifert October 1986 Produces a bag of patterns which will satisfy a given goal ?- bagof(Pattern, Goal, Bag). Keywords: goal, goal satisfaction This predicate produces a Bag of Patterns such that Goal is satisfiable. A "bag" is an unordered set which may contain duplicate elements. 'bagof' is like 'setof' except that it does not order the elements of Bag and allows duplicates. In a query of the form: ?- bagof(Ma, parents(Pa, Ma, Child), B). 'bagof' will treat the meaning of this query as "B is the bag of all Mas such that Pa and Ma are the father and mother of Child for some SPECIFIC Pa and Child". For example, given the database of facts: parents(frances, richard, kathy). parents(elsie, mel, jon). parents(joanne, kenny, frank). we can call 'bagof' as above with the following results: ?- bagof(Ma, parents(Ma, Pa, Child), B). Ma = _1 Pa = kenny Child = frank B = [joanne] ? ; Ma = _1 Pa = mel Child = jon B = [elsie] ? ; Ma = _1 Pa = richard Child = kathy B = [frances] ? ; no Compare with * FAST_BAGOF, * SETOF, and * FAST_SETOF. -- RELATED DOCUMENTATION ---------------------------------------------- PLOGHELP * FAST_BAGOF Fast version of 'bagof' PLOGHELP * SETOF Produces a set of patterns which will satisfy a given goal PLOGHELP * FAST_SETOF Fast version of 'setof' PLOGHELP * FINDALL Library program to find all the terms which satisfy a given predicate