setof/3

Synopsis

setof(+Template, +*Generator, *Set)

Returns the set Set of all instances of Template such that Generator is provable.

Arguments


Template term

Generator callable [MOD]
a goal to be proved as if by call/1.
Set list of term
non-empty set

Description

Set is a set of terms represented as a list of those terms, without duplicates, in the standard order for terms (see ref-lte-cte). If there are no instances of Template such that Generator is satisfied, then setof/3 simply fails.

Obviously, the set to be enumerated should be finite, and should be enumerable by Prolog in finite time. It is possible for the provable instances to contain variables, but in this case Set will only provide an imperfect representation of what is in reality an infinite set.

If Generator is instantiated, but contains uninstantiated variables that do not also appear in Template, then setof/3 can succeed nondeterminately, generating alternative values for Set corresponding to different instantiations of the free variables of Generator. (It is to allow for such usage that Set is constrained to be non-empty.)

If Generator is of the form A^B then all the variables in A are treated as being existentially quantified.

Examples

See findall/3 for examples that illustrate the differences among findall/3, setof/3, and bagof/3.

Exceptions

As for call/1, and additionally:


resource_error
Template contains too many free variables.

See Also

bagof/3, ^/2 ref-all