Did you know ... Search Documentation:
prolog_clause.pl -- Get detailed source-information about a clause
PublicShow source

This module started life as part of the GUI tracer. As it is generally useful for debugging purposes it has moved to the general Prolog library.

The tracer library library(trace/clause) adds caching and dealing with dynamic predicates using listing to XPCE objects to this. Note that clause_info/4 as below can be slow.

Source clause_info(+ClauseRef, -File, -TermPos, -VarOffsets) is semidet
Source clause_info(+ClauseRef, -File, -TermPos, -VarOffsets, +Options) is semidet
Fetches source information for the given clause. File is the file from which the clause was loaded. TermPos describes the source layout in a format compatible to the subterm_positions option of read_term/2. VarOffsets provides access to the variable allocation in a stack-frame. See make_varnames/5 for details.

Note that positions are character positions, i.e., not bytes. Line endings count as a single character, regardless of whether the actual ending is \n or =|\r\n|_.

Defined options are:

variable_names(-Names)
Unify Names with the variable names list (Name=Var) as returned by read_term/3. This argument is intended for reporting source locations and refactoring based on analysis of the compiled code.
Source open_source(+File, -Stream) is semidet[multifile]
Hook into clause_info/5 that opens the stream holding the source for a specific clause. Thus, the query must succeed. The default implementation calls open/3 on the File property.
clause_property(ClauseRef, file(File)),
prolog_clause:open_source(File, Stream)
Source unify_goal(+Read, +Decompiled, +Module, +TermPosRead, -TermPosDecompiled) is semidet[multifile]
This hook is called to fix up source code manipulations that result from goal expansions.
Source initialization_layout(+SourceLocation, ?InitGoal, -ReadGoal, -TermPos) is semidet
Find term-layout of :- initialization directives.
Source predicate_name(:Head, -PredName:string) is det
Describe a predicate as [Module:]Name/Arity.
Source clause_name(+Ref, -Name)
Provide a suitable description of the indicated clause.

Undocumented predicates

The following predicates are exported, but not or incorrectly documented.

Source clause_info(Arg1, Arg2, Arg3, Arg4, Arg5)