write_canonical/[1,2]
write_canonical(
+Term)
write_canonical(
+Stream, +Term)
Writes Term to the current or specified output stream in standard syntax.
Equivalent to
write_term/[2,3]
with the options:
[quoted(true),ignore_ops(true),numbervars(false),char_escapes(false)]
This predicate is provided so that Term, if written to a
file, can be read back by read/[1,2]
regardless of special
characters in Term or prevailing operator declarations.
Does not terminate its output with a full-stop,
which is required by read/[1,2]
.
In general, one can only read (using read/[1,2]
) a term written by
write_canonical/1
if the value of the character_escapes
flag is the
same when the term is read as when it was written.
Stream errors (see ref-iou-sfh-est).
The following sequence will succeed:
... open(FileName, write, StreamOut), write_canonical(StreamOut, Term), write(StreamOut, '.'), nl(StreamOut), close(StreamOut), ... open(FileName, read, StreamIn), read(StreamIn, Term), close(StreamIn), ...
To contrast write/[1,2]
and write_canonical/[1,2]
:
| ?- write({'A' + '$VAR'(0) + [a]}). {A+A+[a]} | ?- write_canonical({'A' + '$VAR'(0) + [a]}). {}(+(+('A','$VAR'(0)),.(a,[])))
write_term/[2,3]
,
write/[1,2]
,
writeq/[1,2]
,
read/[1,2]
ref-iou-tou-cha