[m-dev.] Re: [mercury-users] with_stream

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Nov 15 21:26:53 AEDT 2000


On 15-Nov-2000, Michael Day <mikeday at corplink.com.au> wrote:
> 
> > Regarding the with_stream predicate proposed by Fergus in the recent
> > stream library debate, it seems that it would unnecessarily complicate
> > interactive applications that do not know ahead of time how long they will
> > hold a stream open.
> 
> Alternatively, if a stream is considered to be a handle to some piece of
> state rather than state itself, that would seem to permit the creation of
> a change_stream predicate called from within with_stream that closes the
> current stream and opens a new one.
> 
> with_stream("some filename", predicate, io__states)
> 
> predicate(S0, S) :-
> 	do_stuff(S0, S1),
> 	( if some_condition_holds then
> 		change_stream("some other filename", S1, S2),
> 	else
> 		S2 = S1
> 	),
> 	do_stuff(S2, S3),
> 	predicate(S3, S).
> 
> Presumably change_stream would need to open the new stream *before*
> closing the current stream, in case the new stream doesn't open. This
> might complicate the implementation of with_stream, though I'm not sure
> how much yet. But it or something like it seems necessary if with_stream
> is not to drive people crazy.
> 
> Any thoughts?

That won't work, since `change_stream' followed by `write' will result
in side effects to things other than the state of the original stream.
In other words `change_stream' is impure.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list