Hi all,

Right now we have an 'stdio' variable and various words which operate  
on it,

: read stdio get stream-read ;
: readln stdio get stream-readln ;
: write stdio get stream-write ;
: print stdio get stream-print ;

with-stream rebinds it and closes it after, with-stream* rebinds it  
without closing.

This makes for very nice and concise code, but there's one problem  
with it and that it cannot express the case where you want to read  
from one file and write to another at the same time. Instead, you need  
to do something like this,

"in.txt" utf8 <file-reader> [
     "out.txt" latin1 <file-writer> [
         <duplex-stream> [
             ...
         ] with-stream*
     ] with-disposal
] with-disposal

Or if you want to read from a file and print to the console in the  
same code,

stdio get
"in.txt" utf8 <file-reader> [
     swap <duplex-stream> [
         ...
     ] with-stream*
] with-disposal

This is too awkward for a language named "Factor".

I propose replacing the stdio variable with two variables, input and  
output. The with-stream combinator would still exist, and it would  
bind both, but there will be two new combinators, with-input and with- 
output. These will rebind just one of the two variables.

The stream words would change too: reader words like read, read1,  
would operate on input, and writer words like write and print would  
operate on output.

Note that these changes are pretty much backwards-compatible. Code  
using with-stream continues to work and very rarely does code access  
the stdio variable directly.

A more radical idea is to remove duplex streams altogether. Instead,  
words like <process-stream> and <client> would return a pair of  
streams, a reader and a writer. A with-streams combinator with stack  
effect ( in out quot -- ) could be used here.

Slava

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to