If you want to write out a term and be able to read it back later at any time barring variables names, use the ISO built-in write_canonical/1
or write_canonical/2
. It is quite well supported by current systems. writeq/1
and write/1
work often too, but not always. writeq/1
uses operator syntax (so you need to read it back with the very same operators present) and write/1
does not use quotes. So they work "most of the time" — until they break.
Alternatively, you may use the ISO write-options [quoted(true), ignore_ops(true), numbervars(false)]
in write_term/2
or write_term/3
. This might be interesting to you if you want to use further options like variable_names/1
to retain also the names of the variables.
Also note that the term written does not include a period at the end. So you have to write a space and a period manually at the end. The space is needed to ensure that an atom consisting of graphic characters does not clobber with the period at the end. Think of writing the atom '---'
which must be written as --- .
and not as ---.
You might write the space only in case of an atom. Or an atom that does not "glue" with .