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
. Note also that the printing
of quoted atoms is sensitive to character escaping (see ref-syn-ces).
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,[]))').