[mercury-users] Queries Clarifications for io.m

Ralph Becket rafe at cs.mu.OZ.AU
Tue Nov 26 21:12:48 AEDT 2002


Noel  Pinto, Tuesday, 26 November 2002:
> 
> io__see opens a file for input and sets the current input stream 
> to the new input stream.

Right.

> 1) What I want to know is ... whether the input stream itself is 
> synonymous with the file? i.e. the file could be also called as a 
> stream.

All IO goes via streams.  Some streams are inputs, some are outputs,
some may be both.

Some input streams read from devices (e.g. stdin usually takes its input
from the keyboard), some from files (e.g. opening an ordinary file using
io__see or io__open_input, although at least under Unix, many devices
are also made to look like ordinary files.  Similarly for output
streams.

So a stream is not the same as a file.  A stream is a conduit for data
to pass down.  A file is a source or sink for data.  For instance, I can
open several different streams all reading from (and/or writing to) the
same file.

> 2) Suppose I already have a file open, would it be closed when I 
> try to open another file with io__see?

No.

You should close streams (e.g. with io__seen or io__close_input or
io__told or io__close_output) once you have finished with them: most
operating systems place a limit on the number of streams that a program
can have open at the same time.  You will obtain an error if you attempt
to exceed this number.

Like the C IO operations, the Mercury library provides IO operations for
explicitly named streams (obtained with io__open_input and
io__open_output etc.) and other operations that implicitly send data to
the standard (i.e. currently open) input and output streams.

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



More information about the users mailing list