This package provides a cross reference producer is a useful tool for debugging and program analysis. It can be used to produce the call graph of a program, and to produce a list of predicates that are used but not defined or vice versa. The graph processing utilities described in previous chapters may be used to analyze the call graphs.
To load the package, enter the query
| ?- use_module(library(xref)).
defto every predicate that is explicitly defined, declared, imported, or implicitly defined in a
useto every predicate that is used in a directive, exported, or declared as
public. If a "hook" predicate such as
user:portray/1is defined, there is an edge from
useto it too.
consult/1and friends. The predicate prints on the current output stream a list of predicates which are reachable from
usein the call graph but not defined, followed by a list of predicates which are defined but not reachable from
There may be references not found by
xref because of the dynamic
nature of the Prolog language. Note that
xref does not consider
a predicate used unless it is reachable from a directive, an export
list, or a
public declaration. In non-module files, it is
therefore recommended that the entry point predicates be declared as
public. Predicates reached by meta-calls only may also have to
public to be considered used.
If a module file (file containing a module declaration) is encountered, the module specified is used for that file and subsequent files up to the next module file. This enables packages consisting of several files, which are to be loaded in the same module, to be correctly treated. The type-in module is the default module.
Go to the first, previous, next, last section, table of contents.