write_term/[2,3]
write_term(
+Term,
+Options)
write_term(
+Stream,
+Term,
+Options)
Writes Term to the current output stream or to Stream in a format given by the options.
true
or false
(false
is the default).
quoted(
Bool)
ignore_ops(
Bool)
predicate name(
arg1,...,
argn)
.
portrayed(
Bool)
portray/1
for each
subterm. By default the behavior of write_term/[2,3]
is controlled by
Options, but you can change its effect by providing clauses for
the predicate portray/1
.
character_escapes(
Bool)
true
or false
(the default depends on the value of
the character_escapes
flag as set by prolog_flag/3
). If
Bool is true
then write_term/[2,3]
tries to write layout
characters (except ASCII 9 and ASCII 32) in the form
\
lower-case-letter
, if possible; otherwise, write_term/[2,3]
writes the \^
control-char
form. If Bool is false
then it
writes the actual character, without using an escape sequence.
numbervars(
Bool)
'$VAR'(N)
be treated specially? If Bool is true, write_term/[2,3]
writes A
if N=0, B
if N=1, ...Z
if N=25, A1
if
N=26, etc. Terms of this form are generated by numbervars/3
.
max_depth(
N)
write_term/[2,3]
is the most general of the write family of
predicates. write_term/[2,3]
subsumes all predicates
in the family, with the exception of portray_clause/1
. That is,
all write predicates can be written as calls to write_term/[2,3]
.
domain_error
instantiation_error
type_error
existence_error
permission_error
If an option is specified more than once the rightmost option takes
precedence. This provides for a convenient way of adding default
values by putting these defaults at the front of the list of options.
For example, the predicate my_write_term/2
defined as
my_write_term(Term, Options) :- write_term(Term, [quoted(true), numbervars(true)|Options]).
is equivalent to write_term/2
except that two of the defaults are
different.
How certain options affect the output of write_term/2
:
| ?- write_term('a b', [quoted(true)]). 'a b' | ?- write_term(a+b, [ignore_ops(true)]). +(a,b) | ?- write_term(f('$VAR'(2)), [numbervars(true)].) f(C) | ?- write_term(f('$VAR'('C')), [numbervars(true)]). f(C)
If your intention is to name variables such as that
generated by read_term/2
with the variable_names
option then this can be done by defining a predicate
like:
var_to_names([]) :- !. var_to_names([=(Name,Var)|RestofPairs]) :- ( var(Var) -> Var = '$VAR'(Name) ; true ), var_to_names(RestofPairs). | ?- read_term([variable_names(Names)], X), var_to_names(Names), write_term(X, [numbervars(true)]), nl, fail. |: a(X, Y). a(X, Y). no
write/[1,2]
,
writeq/[1,2]
,
write_canonical/[1,2]
,
display/1
,
print/1
,
portray_clause/1
ref-iou-tou-cha