Joel Reymont wrote:
> May I suggest a variant of with-stream that does _not_ bind stdio?
>
It's easy enough to write one.
: cleanup-stream ( stream quot -- )
over [ stream-close ] curry [ ] cleanup ; inline
Read up on cleanup, recover, catch and throw.
> Suppose I have this word that dumps a bunch of bytes from one file to
> another.
>
> : dump-floats
> 4000000 from-source dup >r stream-read
> to-target dup >r stream-write
> r> stream-close r> stream-close ;
>
> I would like to both print debugging information to stdio and take
> advantage of with-stream to ensure my files are closed in the event of
> an error. It doesn't look like I can accomplish my goals at the moment.
>
You can either do what Chris suggested or you can use cleanup-stream
above. There are many ways to do what you're after here.
Personally I prefer to store logging streams in a log-stream variable
then have a word to write to the log:
: log ( string -- ) log-stream get stream-write ;
Then I use with-stream for the primary stream.
Slava
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk