[mercury-users] Redirecting output to a string (stream)?
Ralph Becket
rafe at cs.mu.OZ.AU
Wed Feb 15 15:37:02 AEDT 2006
doug.auclair at logicaltypes.com, Tuesday, 14 February 2006:
> Dear all,
>
> Is there a way to redirect arbitrarily printed information headed for stdout to a stream that can be read in the same program? Something along the lines of
>
> init_string_stream(Stream),
> write(Stream, T),
> make_readable_n_reset(Stream),
> read(Stream, Term).
>
> Specifically, I do not wish to write out to a file on the file system.
> I'm looking for something like a string_stream. Looking at std_util,
> io, and string, I didn't see anything like that. Is there one
> available? If not, what would it take to implement such a thing?
>
> More directly: can the streams created from extras/stream/ be typed as
> io.output_stream and io.input_stream so that they work directly with
> io.write/4 and io.read/4? Is it possible to create a string_stream
> type that can have BOTH output_stream and input_stream roles as
> illustrated above?
The short answer is "not yet". But we're working on it.
With respect to your earlier e-mail, you really shouldn't be writing out
abstract types and reading them in again as values of different types
that just happen to have the same data constructors. That way lies
madness and divorce, particularly if the library developer decides to
change the private representation. The right solution is to either
extend the library in question or use your own data structure right from
the start.
-- Ralph
--------------------------------------------------------------------------
mercury-users mailing list
post: mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the users
mailing list