print/1
hookableprint(
+Term)
print(
+Stream, +Term)
Writes Term to the current output stream, or Stream.
Can be redefined with the hook portray/1
.
By default, the effect of this predicate is the same as that of
write/1
, but you can change its effect by providing clauses for
the predicate portray/1
.
If Term is a variable, then it is printed using
write(
Term)
.
Otherwise the user-definable procedure
portray(
Term)
is called. If this succeeds, then it is assumed
that Term has been printed and print/1
exits (succeeds).
Note that print/1
always calls portray/1
in module user
.
Therefore, to be visible to print/1
, portray/1
must either be
defined in or imported into module user
.
If the call to portray/1
fails, and if Term is a compound term, then
write/1
is used to write the principal functor of Term and
print/1
is called recursively on its arguments. If Term
is atomic, it is written using write/1
.
When print/1
has to print a list, say [Term1,Term2,...,TermN], it passes
the whole list to portray/1
. As usual, if portray/1
succeeds,
it is assumed to have printed the entire list, and print/1
does
nothing further with this term. Otherwise print/1
writes the
list using bracket notation, calling print/1
on each element of the
list in turn.
Since [Term1,Term2,...,TermN] is simply a different way of
writing .(Term1,[Term2,...,TermN]), one might expect print/1
to be called
recursively on the two arguments Term1 and [Term2,...,TermN], giving portray/1
a second
chance at [Term2,...,TermN]. This does not happen; lists are a
special case in which print/1
is called separately for each of
Term1,Term2,...TermN.
If you would like lists of character codes printed
by print/1
using double-quote notation, you should
include library(printchars)
(see lib-abs)
as part of your version of portray/1
.
Succeeds without error, except for any errors
that may occur in the execution of portray/1
.
portray/1
, library(printchars)