[ All Solutions | 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.
Prolog term, usually a variable, a compound term or list containing variables.
Callable term.
List or variable.


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


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

Fail Conditions

Fails if Goal has no solution


(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.



   % example using existential quantification:
  [eclipse]: [user].
   user compiled 900 bytes in 0.00 seconds

  [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)]
  coverof(X,G,L).         (Error 4).
  coverof(X,"G",L).       (Error 5).
  coverof(X,a,L).         (Error 68).

See Also

bagof / 3, findall / 3, setof / 3