[m-rev.] io__read_file_as_string (was: improve `_init.c' file creation)

Simon Taylor stayl at cs.mu.OZ.AU
Wed Nov 28 23:49:15 AEDT 2001


On 28-Nov-2001, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> On 28-Nov-2001, Simon Taylor <stayl at cs.mu.OZ.AU> wrote:
> > > > +		% XXX Why does `io__read_file_as_string' return a separate
> > > > +		% status and result, rather than an `io__res(string)'?
> > > 
> > > The reason is to ensure that, in the case when some characters are
> > > successfully read and then an I/O error occurs, the part of the file
> > > that was successfully read can be returned.
> > 
> > When is that behaviour useful?
> 
> When the error is something such as EINTR.
> 
> When implementing programs such as `cat', which should output all that
> it successfully reads before reporting a read error.
 
`io__read_file' is inappropriate for this kind of application
because the size of the input is not bounded. The interface
should not encourage that kind of use.

> When the error occurs because the input file is `stdin',
> and the user's dialup connection has just been disconnected
> due to a Telstra fault.  The data may be hard for the user
> to reproduce, so the program should not just throw it away.

Applications taking user input from stdin generally don't use
`io__read_file' to read it.

> > It also doesn't
> > force the user to check for errors before using the result like all
> > the other input predicates do (including `io__read_file'). It might be
> > better to use a different result type like the one below,
> 
> I could live with that.
> 
> > but I think
> > the best solution is just to return an `io__res(string)' and throw away
> > the partially read data.
> 
> I couldn't live with that.

I still disagree. I can't think of an application where a partial read
of a file is useful that wouldn't be better done using character at a
time input.

Simon.
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list