Writes Term to the current output stream or to Stream in a format given by the options.
falseis the default).
portray/1for 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
false(the default depends on the value of the
character_escapesflag as set by
prolog_flag/3). If Bool is
write_term/[2,3]tries to write layout characters (except ASCII 9 and ASCII 32) in the form
, if possible; otherwise,
form. If Bool is
falsethen it writes the actual character, without using an escape sequence.
'$VAR'(N)be treated specially? If Bool is true,
Bif N=1, ...
A1if N=26, etc. Terms of this form are generated by
write_term/[2,3] is the most general of the write family of
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
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
How certain options affect the output of
| ?- 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
read_term/2 with the variable_names
option then this can be done by defining a predicate
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