- Documentation
- Reference manual
- The SWI-Prolog library
- library(aggregate): Aggregation operators on backtrackable predicates
- library(ansi_term): Print decorated text to ANSI consoles
- library(apply): Apply predicates on a list
- library(assoc): Association lists
- library(broadcast): Broadcast and receive event notifications
- library(charsio): I/O on Lists of Character Codes
- library(check): Consistency checking
- library(clpb): CLP(B): Constraint Logic Programming over Boolean Variables
- library(clpfd): CLP(FD): Constraint Logic Programming over Finite Domains
- library(clpqr): Constraint Logic Programming over Rationals and Reals
- library(csv): Process CSV (Comma-Separated Values) data
- library(dcg/basics): Various general DCG utilities
- library(dcg/high_order): High order grammar operations
- library(debug): Print debug messages and test assertions
- library(dicts): Dict utilities
- library(error): Error generating support
- library(fastrw): Fast reading and writing of terms
- library(gensym): Generate unique symbols
- library(heaps): heaps/priority queues
- library(increval): Incremental dynamic predicate modification
- library(intercept): Intercept and signal interface
- library(iostream): Utilities to deal with streams
- library(listing): List programs and pretty print clauses
- library(lists): List Manipulation
- library(macros): Macro expansion
- library(main): Provide entry point for scripts
- library(nb_set): Non-backtrackable set
- library(www_browser): Open a URL in the users browser
- library(occurs): Finding and counting sub-terms
- library(option): Option list processing
- library(optparse): command line parsing
- library(ordsets): Ordered set manipulation
- library(pairs): Operations on key-value lists
- library(persistency): Provide persistent dynamic predicates
- library(pio): Pure I/O
- library(portray_text): Portray text
- library(predicate_options): Declare option-processing of predicates
- library(prolog_coverage): Coverage analysis tool
- library(prolog_debug): User level debugging tools
- library(prolog_jiti): Just In Time Indexing (JITI) utilities
- library(prolog_trace): Print access to predicates
- library(prolog_versions): Demand specific (Prolog) versions
- library(prolog_xref): Prolog cross-referencer data collection
- library(quasi_quotations): Define Quasi Quotation syntax
- library(random): Random numbers
- library(rbtrees): Red black trees
- library(readutil): Read utilities
- library(record): Access named fields in a term
- library(registry): Manipulating the Windows registry
- library(rwlocks): Read/write locks
- library(settings): Setting management
- library(statistics): Get information about resource usage
- library(strings): String utilities
- library(simplex): Solve linear programming problems
- library(solution_sequences): Modify solution sequences
- library(tables): XSB interface to tables
- library(terms): Term manipulation
- library(thread): High level thread primitives
- library(thread_pool): Resource bounded thread management
- library(ugraphs): Graph manipulation library
- library(url): Analysing and constructing URL
- library(varnumbers): Utilities for numbered terms
- library(yall): Lambda expressions
- The SWI-Prolog library
- Packages
- Reference manual
A.23 library(listing): List programs and pretty print clauses
- To be done
- - More settings, support Coding Guidelines for Prolog and make
the suggestions there the default.
- Provide persistent user customization
This module implements listing code from the internal representation in a human readable format.
- listing/0 lists a module.
- listing/1 lists a predicate or matching clause
- listing/2 lists a predicate or matching clause with options
- portray_clause/2 pretty-prints a clause-term
Layout can be customized using library(settings)
. The
effective settings can be listed using list_settings/1
as illustrated below. Settings can be changed using set_setting/2.
?- list_settings(listing). ======================================================================== Name Value (*=modified) Comment ======================================================================== listing:body_indentation 4 Indentation used goals in the body listing:tab_distance 0 Distance between tab-stops. ...
- listing
- Lists all predicates defined in the calling module. Imported predicates
are not listed. To list the content of the module
mymodule
, use one of the calls below.?- mymodule:listing. ?- listing(mymodule:_).
- [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) orgenerated
. Ifsource
, 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
(defaultfalse
), 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)]).
- Predicate indicator (Name/Arity or Name
- [det]portray_clause(+Clause)
- [det]portray_clause(+Out:stream, +Clause)
- [det]portray_clause(+Out:stream, +Clause, +Options)
- Portray‘Clause’on the current output stream.
Layout of the clause is to our best standards. Deals with control
structures and calls via meta-call predicates as determined using the
predicate property meta_predicate. If Clause contains
attributed variables, these are treated as normal variables.
Variable names are by default generated using numbervars/4 using the option
singletons(true)
. This names the variables A, B, ... and the singletons _. Variables can be named explicitly by binding them to a term'$VAR'(Name)
, where Name is an atom denoting a valid variable name (see the optionnumbervars(true)
from write_term/2) as well as by using thevariable_names(Bindings)
option from write_term/2.Options processed in addition to write_term/2 options:
- variable_names(+Bindings)
- See above and write_term/2.
- indent(+Columns)
- Left margin used for the clause. Default
0
. - module(+Module)
- Module used to determine whether a goal resolves to a meta
predicate. Default
user
.