A.23 library(listing): List programs and pretty print clauses
AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
      • The SWI-Prolog library
        • library(listing): List programs and pretty print clauses
          • listing/0
          • listing/1
          • listing/2
          • portray_clause/1
          • portray_clause/2
          • portray_clause/3
    • Packages
Availability::- use_module(library(listing)).(can be autoloaded)
Source[det]listing(:What)
[det]listing(:What, +Options)
List matching clauses. What is either a plain specification or a list of specifications. Plain specifications are:

  • Predicate indicator (Name/Arity or Name//Arity) Lists the indicated predicate. This also outputs relevant declarations, such as multifile/1 or dynamic/1.
  • A Head term. In this case, only clauses whose head unify with Head are listed. This is illustrated in the query below that only lists the first clause of append/3.
    ?- listing(append([], _, _)).
    lists:append([], L, L).

  • A clause reference as obtained for example from nth_clause/3.

The following options are defined:

variable_names(+How)
One of source (default) or generated. If source, for each clause that is associated to a source location the system tries to restore the original variable names. This may fail if macro expansion is not reversible or the term cannot be read due to different operator declarations. In that case variable names are generated.
source(+Bool)
If true (default false), extract the lines from the source files that produced the clauses, i.e., list the original source text rather than the decompiled clauses. Each set of contiguous clauses is preceded by a comment that indicates the file and line of origin. Clauses that cannot be related to source code are decompiled where the comment indicates the decompiled state. This is notably practical for collecting the state of multifile predicates. For example:
?- listing(file_search_path, [source(true)]).