[ All Solutions | The ECLiPSe Built-In Predicates | Reference Manual | Alphabetic Index ]

# coverof(?Term, +Goal, -List)

Succeeds if List is the (non-empty) list of all the most general instances of Term such that Goal is provable.
Term
Prolog term, usually a variable, a compound term or list containing variables.
Goal
Callable term.
List
List or variable.

## Description

Unifies List with the list (not ordered, duplicates removed, pruned) of all instances of Term such that Goal is satisfied. prune_instances/2 is used on the list of solutions, with the result that no element of List is an instance of any other element.

The variables appearing in Term should not appear anywhere else in the clause except within Goal.

The following table illustrates the difference between the all solutions predicates:

```    built-in  choice pts  duplicates  sorted pruned *
bagof/3   yes         yes         no     no
coverof/3 yes         no          no     yes
findall/3 no          yes         no     no
setof/3   yes         no          yes    no
* prune_instances/2 used on list of solutions.
```
If Goal is not a callable term, exceptions are raised in call/2.

coverof/3 should not be used if Term is a variable. If the resulting list List contains no compound terms or variables, it is usually more efficient to use setof/3.

Note If there are uninstantiated variables in Goal which do not appear in Term, then coverof/3 can be resatisfied. It generates alternative values for List corresponding to different instantiations of the free variables of Goal not in Term. Such variables occurring in Goal will not be treated as free if they are explicitly bound within Goal through an existential quantification written as, for example,

```   coverof(X, Y^(X likes Y), S).
```
Then coverof/3 will not backtrack over Y when getting a list of solutions of X.

### Modes and Determinism

• coverof(?, +, -) is nondet

### Modules

This predicate is sensitive to its module context (tool predicate, see @/2).

### Fail Conditions

Fails if Goal has no solution

### Exceptions

(4) instantiation fault
Goal is not instantiated.
(5) type error
Goal is instantiated, but not to a compound term.
(68) calling an undefined procedure
Goal is an undefined procedure.

## Examples

```Success:

% example using existential quantification:
[eclipse]: [user].
h(f(1,2),g(1,3)).
h(f(2,3),g(2,4)).
h(f(1,3),g(2,2)).
h(f(2,3),g(2,2)).
h(f(2,2),g(1,1)).
user compiled 900 bytes in 0.00 seconds

yes.
[eclipse]: coverof(f(X,Y),h(f(X,Y),g(W,Z)),L),
> writeln((X,Y,W,Z,L)), fail.
_g66 , _g72 , 1 , 1 , [f(2, 2)]
_g66 , _g72 , 1 , 3 , [f(1, 2)]
_g66 , _g72 , 2 , 2 , [f(1, 3), f(2, 3)]
_g66 , _g72 , 2 , 4 , [f(2, 3)]

no (more) solution.
[eclipse]: coverof(f(X,Y),g(W,Z)^h(f(X,Y),g(W,Z)),L).
X = _g76
Y = _g78
W = _g70
Z = _g72
L = [f(1, 2), f(2, 3), f(1, 3), f(2, 2)]
yes.
Fail:
coverof(Y,current_stream(X,Y,Z),[strin]).
Error:
coverof(X,G,L).         (Error 4).
coverof(X,"G",L).       (Error 5).
coverof(X,a,L).         (Error 68).

```