[m-dev.] io streams
Michael Day
mcda at cat.cs.mu.OZ.AU
Fri Dec 24 12:05:08 AEDT 1999
> Well, in many modern languages you don't have to close files at all;
> the system handlers that automatically. Having the compiler sometimes
> optimize away some or all of your output is not a very nice feature.
> If we're going to require that users close streams manually, it would
> be nicer if we could detect at compile time if they fail to do so.
It seems that automatic file closing would be easy if the C interface
could be used to provide a hook for when the last reference to a variable
expires. I'm not quite sure how it could be done otherwise, as the user
could just drop the file handle at any time. I would prefer explicit file
closing, it seems to have a clearer meaning to me, but I'm not sure how to
detect missing closes at compile time. Perhaps when the file is opened,
transform the io__state into something else and turn it back into an
io__state when the file is closed. This would seem to prevent missing
closes, but would also prevent any other files being opened or other forms
of io being done simultaneously. Something along those lines perhaps...
> Well, you shouldn't assume that Mercury's `char' type is 8 bits.
> We might well change Mercury's `char' type so that it corresponds
> to C's `wchar_t' type or some other type for Unicode characters.
> If this interface is intended for byte-level I/O, then you should
> define a `byte' type and use that, rather than using `char'.
Yes, I'm still a bit uncertain about what the basic unit of input and
output should be. I'm tempted to try something like:
write_char(C, S, S) <= (character(C), stream__output(S))
which would appear to offer convenient usage, and avoid the problems I
mentioned earlier of writing to unicode strings and similar. But it smells
inefficient, I can't think of a sensible definition for the character type
class that would be convenient to implement. Worth a try perhaps.
Michael
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list