I/O example

matthews@math.uga.edu matthews@math.uga.edu
Thu, 21 Jan 1999 14:16:18 -0500 (EST)


Many thanks to those who sent me I/O examples showing me how to read in
a file into a list of chars, munge it, and then write it out. Very
very helpful.

As a followup query Artie wrote the following to me:
> Also, your comment about "I want to read it into a list because it's
> small" (or something to that effect) requires further examination--think
> in terms of lazy evaluation. The WHOLE list of input may never need to 
> exist all at once (as long as it's unique). So the size of the input 
> doesn't matter.

I realise that lazy evaluation may mean the the while list may never
need to exist at once, but in this case I wondered if the presence of
I/O may force the whole list to be constructed. To be more specific
my example was as follows,

1) read a file into a list of chars.
2) munge the list a bit.
3) write the list out to another file.

If step 1) is done lazily then there is a potential problem -- namely
that step 3) overwrites the file I am reading from, making a mess. Hence
I wondered if the presence of the I/O forces step 1) to be done strictly
and hence the whole list does exist at once. Or does Clean avoid this
problem without losing laziness, by not allowing a write to a file that
is already open for a read?

graham