% This LaTeX document was generated using the LaTeX backend of PlDoc,
% The SWI-Prolog documentation system



\section{library(check): Consistency checking}

\label{sec:check}

\begin{tags}
\mtag{See also}- \predref{gxref}{0} provides a graphical cross referencer \\- PceEmacs performs real time consistency checks while you edit \\- \verb$library(prolog_xref)$ implements `offline' cross-referencing \\- \verb$library(prolog_codewalk)$ implements `online' analysis
\end{tags}

This library provides some consistency checks for the loaded Prolog
program. The predicate \predref{make}{0} runs \predref{list_undefined}{0} to find undefined
predicates in `user' modules.\vspace{0.7cm}

\begin{description}
    \predicate[det]{check}{0}{}
Run all consistency checks defined by \predref{checker}{2}. Checks enabled by
default are:

\begin{itemize}
    \item \predref{list_undefined}{0} reports undefined predicates
    \item \predref{list_trivial_fails}{0} reports calls for which there is no
matching clause.
    \item \predref{list_redefined}{0} reports predicates that have a local
definition and a global definition. Note that these are
\textbf{not} errors.
    \item \predref{list_autoload}{0} lists predicates that will be defined at
runtime using the autoloader.
\end{itemize}

    \predicate[det]{list_undefined}{0}{}
\nodescription
    \predicate[det]{list_undefined}{1}{+Options}
Report undefined predicates. This predicate finds undefined
predicates by decompiling and analyzing the body of all clauses.
\arg{Options}:

\begin{description}
    \termitem{module_class}{+Classes}
Process modules of the given \arg{Classes}. The default for
classes is \verb$[user]$. For example, to include the
libraries into the examination, use \verb$[user,library]$.
\end{description}

\begin{tags}
\mtag{See also}- \predref{gxref}{0} provides a graphical cross-referencer. \\- \predref{make}{0} calls \predref{list_undefined}{0}
\end{tags}

    \predicate[det]{list_autoload}{0}{}
Report predicates that may be auto-loaded. These are predicates
that are not defined, but will be loaded on demand if
referenced.

\begin{tags}
    \tag{See also}
\predref{autoload}{0}
    \tag{To be done}
This predicate uses an older mechanism for finding
undefined predicates. Should be synchronized with
list undefined.
\end{tags}

    \predicate{list_redefined}{0}{}
Lists predicates that are defined in the global module \const{user} as
well as in a normal module; that is, predicates for which the
local definition overrules the global default definition.

    \predicate[det]{list_void_declarations}{0}{}
List predicates that have declared attributes, but no clauses.

    \predicate[det]{list_trivial_fails}{0}{}
\nodescription
    \predicate[det]{list_trivial_fails}{1}{+Options}
List goals that trivially fail because there is no matching
clause. \arg{Options}:

\begin{description}
    \termitem{module_class}{+Classes}
Process modules of the given \arg{Classes}. The default for
classes is \verb$[user]$. For example, to include the
libraries into the examination, use \verb$[user,library]$.
\end{description}

    \predicate[multifile]{trivial_fail_goal}{1}{:Goal}
Multifile hook that tells \predref{list_trivial_fails}{0} to accept \arg{Goal} as
valid.

    \predicate[det]{list_strings}{0}{}
\nodescription
    \predicate[det]{list_strings}{1}{+Options}
List strings that appear in clauses. This predicate is used to
find portability issues for changing the Prolog flag
\verb$double_quotes$ from \const{codes} to \const{string}, creating packed string
objects. Warnings may be suppressed using the following
multifile hooks:

\begin{itemize}
    \item \predref{string_predicate}{1} to stop checking certain predicates
    \item \predref{valid_string_goal}{1} to tell the checker that a goal is
safe.
\end{itemize}

\begin{tags}
    \tag{See also}
Prolog flag \verb$double_quotes$.
\end{tags}

    \predicate[multifile]{string_predicate}{1}{:PredicateIndicator}
Multifile hook to disable \predref{list_strings}{0} on the given predicate.
This is typically used for facts that store strings.

    \predicate[semidet,multifile]{valid_string_goal}{1}{+Goal}
Multifile hook that qualifies \arg{Goal} as valid for \predref{list_strings}{0}.
For example, \verb$format("Hello world~n")$ is considered proper use of
string constants.

    \predicate[multifile]{checker}{2}{:Goal, +Message:text}
Register code validation routines. Each clause defines a \arg{Goal}
which performs a consistency check executed by \predref{check}{0}. \arg{Message}
is a short description of the check. For example, assuming the
\verb$my_checks$ module defines a predicate \predref{list_format_mistakes}{0}:

\begin{code}
:- multifile check:checker/2.
check:checker(my_checks:list_format_mistakes,
              "errors with format/2 arguments").
\end{code}

The predicate is dynamic, so you can disable checks with \predref{retract}{1}.
For example, to stop reporting redefined predicates:

\begin{code}
retract(check:checker(list_redefined,_)).
\end{code}

\end{description}

