Re: write_canonical and streams
Jan Wielemaker <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <[email protected]> |
On 02/11/2014 05:09 PM, Wouter Beek wrote:
> Hi Prologgers,
>
> The documentation for `write_canonical/[1,2]` states that "Terms
> written with this predicate can always be read back [...]"
>
> But for error terms that include a stream alias I get the following
> when reading back:
> ~~~{.pl}
> read_term_from_atom('error(io_error(read,<stream>(0x7ff649a6d830)),context(:(read_util,/(read_line_to_codes,2)),\'Connection
> reset by peer\'))', Term, []).
> ERROR: Syntax error: Operator expected
> ERROR: error(io_error(read,<
> ERROR: ** here **
> ERROR: stream>(0x7ff649a6d830)),context(:(read_util,/(read_line_to_codes,2)),'Connection
> reset by peer')) .
> ~~~
>
> Does canonical writing not work for stream aliases or am I making some
> other mistake?
You are not really making a mistake. Stream handles (and various
other handles to internal data structures) are some form of
out-of-band data. They are written in a syntax that does not read
back and deliberately so because this means that the system *knows*
which handles are valid and referenced and can GC the underlying
data structures. If we allowed for read/write, we can never know
because the term can `leave' the system and get back into the
system by reading it.
One could argue that quoted write should refuse to write the term
instead of read refusing to read it.
library(pengines) defines replace_blobs/2, which is used for error
terms and replaces these special terms with a quoted atom.
Cheers --- Jan