[plt-scheme] interleaving the I and O in I/O

From: Prabhakar Ragde (plragde at uwaterloo.ca)
Date: Fri Feb 1 10:51:32 EST 2008

In response to my question on why alternating reads and printfs (instead 
of doing all the printfs later) slowed down a program, Matthew Flatt 
wrote on January 27:

> When you read from the original input port, the original output port is
> automatically flushed. So, the first version writes line-by-line, while
> the second writes the list in blocks. I think that accounts for the
> time difference.
> I note that there's another layer of automatic behavior here, which is
> that block buffering for output is enabled because output is directed
> to a file, as opposed to a tty.
> For 4.0, we should reconsider auto-flush of the current output port
> when reading from the current input port. Maybe it should only happen
> when the output is a tty. It's also awkward that the behavior is tied
> to the original ports, but that's another part of the trade-off in
> performance and expected behavior, and it will probably stay.

So, a followup I should have asked at the time: is there any way for the 
user to modify this behaviour? Specifically, I want to avoid having the 
current output port flushed every time there is a read. --PR

Posted on the users mailing list.