This is a generalisation of the predicates write/2, writeq/2, print/2, display/2, write_canonical/2. It is used to write an arbitrary term Term onto the current output stream according to the given options. Options is a (possibly empty) list of the following options:
do not assume any particular meaning of the printed term.
print the term as a clause, i.e. clause macros will be taken into account.
print the term as a goal, i.e. goal write transformations will be taken into account.
do not print any variable attributes, i.e. print attributed variables like plain variables.
variable attributes are printed using the corresponding print handlers. See meta_attribute/2.
print the full contents of all variable attributes. This is necessary if the term is to be written out and read back in.
print extra blank space (around operators, after commas, etc.) for better readability.
don't print blank space unless necessary.
print the term only up to a maximum nesting depth determined by the (stream-specific or global) flag 'print_depth'. See get_stream_info/3 and get_flag/2.
print the term only up to a maximum nesting depth of MaxDepth. MaxDepth is a positive integer.
do not observe any depth limit and print the whole term. Note that this will cause looping when the term is cyclic.
write lists in the common square bracket notation, e.g. [1, 2].
write lists in the dot functor notation rather than using the square bracket notation, e.g. .(1, .(2, )) rather than [1, 2].
print newline (NL) characters as escape sequence, when they occur in quoted atoms or strings.
print newline (NL) characters as newlines rather than as an escape sequence, even when they occur in quoted atoms or strings. This only makes sense together with the quoted(true) option.
do not treat '$VAR'/1 terms specially. ISO-Prolog compatible.
any term of the form '$VAR'(N), where N is a non-negative integer, is printed as a variable name consisting of a capital letter followed by a number. The capital letter is the ((N mod 26)+1)st letter of the alphabet, and the integer is N//26. If N is an atom, this atom gets printed instead of the term. ISO-Prolog compatible.
obey operator declarations. All infix, prefix and postfix operators are printed in infix, prefix or postfix form, respectively.
ignore operator declarations. All terms are written in the canonical notation, with a functor followed by the arguments in parentheses.
do not use portray/1,2.
call the user-defined predicate portray/1,2 in the way print/1,2 does.
do not print quotes around strings or atoms. ISO-Prolog compatible.
quote atoms and strings if necessary. ISO-Prolog compatible.
apply portray (write) transformations before printing.
do not apply any portray (write) transformations.
print variables using their source name, if available.
Otherwise print a system-generated name, which consists of
an underscore and a number, e.g.
Note that this format cannot be reliably read back, because
different variables may have the same source name.
print all variables using a system-generated name, which
consists of an underscore and a number, e.g.
This format is suitable when the term needs to be read back
later. It makes sure that multiple occurrences of the same
variable have the same name, and different variables have
print variables using their source name, if available, followed by a unique number, e.g. Alpha_132. Variables without source name are printed in the raw format. Since variables with identical source names are named apart, this format is suitable when the term needs to be read back later.
print every variable as a simple underscore. Any information about multiple occurrences of a variable is lost with this format. It is mainly useful to produce output that can be compared easily with the output of a different Eclipse session.
When an option is omitted altogether, then the corresponding option settings for the output stream will come into effect (see set_stream_property/3, get_stream_info/3, open/4).The following additional options are supported for compatibility with other Prolog systems:
the same as [operators(false),dotlists(true),transform(false)]. ISO-Prolog compatibility.
the same as [operators(true),dotlists(false),transform(true)]. ISO-Prolog compatibility.
the same as depth(full). SICStus-Prolog compatibility.
the same as depth(N). SICStus-Prolog compatibility.
write_term(T, [variables(raw),attributes(full),transform(false), quoted(true),depth(full)])
write_term(T, [variables(raw),attributes(full),transform(false), quoted(true),depth(full),dotlist(true),operators(false)])
Note that as usual, the output is buffered, so it may need to be flushed either by closing the stream, by writing again or by using flush/1.
?- write_term(*(^(1,2),+(3,4)), ). 1 ^ 2 * (3 + 4) ?- write_term(*(^(1,2),+(3,4)), [operators(false)]). *(^(1, 2), +(3, 4)) ?- write_term(['a-b',"cd"], ). [a-b, cd] ?- write_term(['a-b',"cd"], [quoted(true)]). ['a-b', "cd"] ?- write_term(['a-b',"cd"], [quoted(true),dotlists(true)]). .('a-b', .("cd", ))