write
and writeq
the term is written with respect to
current operator declarations (See ref-syn-ops, for a discussion
of operators).
write_canonical(
Term)
writes Term to the current or specified output stream
in standard syntax (see ref-syn on Prolog syntax),
and quotes atoms and functors to make them acceptable as input to
read/[1,2]
. That is, operator declarations are not used and compound
terms are therefore always written in the form:
predicate_name(arg1, ..., argn)
write/[1,2]
cannot in general be read back using
read/[1,2]
. For example,
| ?- write('a b'). a b
If you want to be sure that the atom can be read back by read/[1,2]
, you
should use writeq/[1,2]
, or write_canonical/[1,2]
, which put
quotes around atoms when necessary, or use write_term/[2,3]
with the
quoted
option set to yes
.
write/[1,2]
and writeq/[1,2]
treat terms of the form '$VAR'(
N)
specially: they write 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
(see ref-lte-anv). Terms of the form '$VAR'(
X)
,
where X is not a number are written as unquoted terms. For example,
| ?- writeq(a('$VAR'(0),'$VAR'('Test'))). a(A,Test)
write_canonical/1
does not treat terms of the form '$VAR'(
N)
specially. It writes square bracket lists using ./2
and
[]
(that is, [a,b]
is written as .(a,.(b,[]))
). If the
character_escapes
flag is on
then write_canonical/1
tries to
write layout characters (except ASCII 9 and ASCII 32) in the form
\
lower-case-letter, if possible; otherwise,
write_canonical/1
writes the \^
control-char form. If the
character_escapes
flag is
off
then it writes the actual character, without using an escape
sequence (see ref-syn-ces).
writeq/[1,2]
and write_canonical/[1,2]
behave differently
when writing quoted atoms. If character escaping is on:
\
lowercase letter
form.
\^
control char
form.
If character escaping is off:
read/[1,2]
) a term written by
write_canonical/[1,2]
if the value of the character_escapes
flag is the
same when the term is read as when it was written.