It'd end up being more awkward to use something like that, where the
stream is on the stack, because then you'd have to pass it around to
different words explicitly. Of course, it's possible to implement
something like with-open-file; we're just not going to put it in the
core for that reason. More concretely, for this purpose, it might be a
pattern to log in the outer stream and set a new inner stream (like a
file) as stdio. For this we could define a combinator
with-stream-logging something like this:

: with-log-stdio ( stream quot -- )
    stdio get [ with-stream ] with-log-stream ; inline

Also, for complex I/O in the log stream, you can do something like this:

: in-log ( quot -- )
    log-stream get stdio rot with-variable ; inline

so then you could write your code as

myfile <file-reader-writer-whatever> [
   "foo" . #! writes to file
   "foo" log-message #! writes to stdio
   [ "foo" . ..blahblah.. ] in-log #! more complex stdio output
] with-log-stdio

(I'm sure there's a better name for with-log-stdio)

Dan

On Jan 25, 2008 7:27 AM, Joel Reymont <[EMAIL PROTECTED]> wrote:
> Thank you Chris! I still insist that the current implementation is a
> PITA compared to Lisp's  with-open-file.
>
>
> --
> http://wagerlabs.com

-------------------------------------------------------------------------
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

Reply via email to