Re: write_canonical and streams

Wouter Beek <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <CAE1un7OKsyU0oFX+Gr-HDDrQeCNJEPzsiqSF4WbFOa3eZPAbkw@mail.gmail.com>
Hi Richard, Jan, Anne,

Thanks for the responses!
Indeed I mixed up aliases with handles, thanks for pointing that out.

I'm now trying to use option `blob` in `write_term/[2,3]` but it's not
working for me yet. I would like to write (compound terms containing)
stream handles in such a way that I'm able to read the result back
later without any errors. I'm not particularly interested in what is
written to replace the stream handle, e.g. the atom `monkey` would
suffice for my current purposes.

Here is my attempt at using portray which is not working yet:
~~~{.pl}
portray(Term):-
  (is_stream(Term) ; blob(Term, stream)), !,
  write(monkey).

test:-
  open('README.md', read, Stream),
  write_term(Stream, [blob(portray)]),
  nl,
  halt.
~~~

The above code outputs [1], while I would like to have [2].
~~~{.pl}
[1]   <stream>(0x200b590)
[2]   monkey
~~~

Cheers!,
Wouter.

E-mail: [email protected]
WWW: www.wouterbeek.com
Tel.: 0647674624


On Wed, Feb 12, 2014 at 12:41 AM, Richard A. O'Keefe <[email protected]> wrote:
>
> On 12/02/2014, at 7:53 AM, Anne Ogborn wrote:
>
>>> One could argue that quoted write should refuse to write the term
>>
>> instead of read refusing to read it.
>>
>>
>> I'd argue for that. Breaking the contract that you can always read what you've
>> written is definitely in ROK's 'almost works' territory.
>
> For debugging purposes, it's great to be able to see _everything_,
> and at least to know what _kind_ of thing a term was.
>
> Note that SWI has a blob(Atom) write-option.
> I don't actually understand how to use it, but
> I imagine you could use it to raise an exception.
>
> For what it's worth,
>  - The <...> notation seems to be straight of out Lisp,
>    where #<...> is used for things that don't read back,
>    and the lexical macro #< is basically defined to raise
>    an exception.
>  - Quintus used special '$stream'(..,..) terms and similar terms
>    for data base references, &c, that *could* be read back, and
>    *could* be safely used when read back, provided the "object"
>    referred to still existed.  Basically, the arguments of the
>    term let you find the original object and also gave a quasi-
>    random "secret key" so that you could tell if it was still
>    the "same" object.  A more modern equivalent would be to
>    use a UUID.
>
> The point of mentioning Quintus here is that it shows that
> you COULD have a printable representation for "object references"
> that DID read back.  The price of that is that you have to
> distinguish between
>         "well formed" references
> and
>         "still valid" references.
>
>
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.