Next: ref-iou-tou-dsp, Previous: ref-iou-tou-cha, Up: ref-iou-tou [Contents][Index]
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 always written in the form:
name(arg1, …, argn)
and the special list syntax, e.g. [a,b,c]
, or
braces syntax, e.g. {a,b,c}
are not used.
Calling write_canonical/1
is a good way of finding out how Prolog parses a term
with several operators.
write/[1,2]
cannot in general be read back using
read/[1,2]
. For example,
| ?- write('a b'). a b
For this reason write/[1,2]
is only useful as a way to treat
atoms as strings of characters. It is rarely, if ever, useful to use
write/[1,2]
with other kinds of terms, i.e. variables,
numbers or compound terms.
If you want to be sure that the atom can be read back by read/[1,2]
, then 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 true
.
Note also that the printing
of quoted atoms is sensitive to character escaping (see ref-syn-ces).
write/[1,2]
and writeq/[1,2]
use the write option
numbervars(true)
, so 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).
| ?- writeq(a('$VAR'(0),'$VAR'(1))). a(A,B)
write_canonical/1
does not treat terms of the form '$VAR'(N)
specially.