23.  Ports and Files  

Generally, a file name can either be a string or a symbol. If a symbol is given, it is converted into a string by applying symbol->string. A tilde at the beginning of a file name is expanded according to the rules employed by the C-Shell (see csh(1)).

Elk adds a third type of ports, input-output (bidirectional) ports. Both input-port? and output-port? return #t when applied to an input-output port, and both input primitives and output primitives may be applied to input-output ports. An input-output port (in fact, any port) may be closed with any of the primitives close-input-port and close-output-port.

The only way to create an input-output-port is by means of the procedure open-input-output-file. Extensions may provide additional means to create bidirectional ports.

(call-with-input-file file procedure)
(call-with-output-file file procedure)

See R^4RS.

(input-port? obj)
(output-port? obj)

See R^4RS.

(current-input-port)
(current-output-port)

See R^4RS.

(with-input-from-file file thunk)
(with-output-to-file file thunk)

See R^4RS.
file can be a string as well as a symbol.

(open-input-file file)
(open-output-file file)
(open-input-output-file file)

See R^4RS.
file can be a string as well as a symbol. open-input-output-file opens the file for reading and writing and returns an input-output port; the file must exist and is not truncated.

(close-input-port port)
(close-output-port port)

See R^4RS.
Calls to close-input-port and close-output-port are ignored when applied to string ports or to ports connected with the standard input or standard output of the process.

(clear-output-port)
(clear-output-port output-port)

If the argument is omitted, it defaults to the current output port.
In case of ``buffered'' output, this procedure is used to discard all characters that have been output to the port but have not yet been sent to the file associated with the port.

(flush-output-port)
(flush-output-port output-port)

If the argument is omitted, it defaults to the current output port.
In case of ``buffered'' output, this procedure is used to force all characters that have been output to the port to be printed immediately. This may be necessary to force output that is not terminated with a newline to appear on the terminal. An output port is flushed automatically when it is closed.

(clear-input-port)
(clear-input-port input-port)

If the argument is omitted, it defaults to the current input port.
In case of ``buffered'' input, this procedure discards all characters that have already been read from the file associated with the port but have not been processed using read or similar procedures.

(port-file-name port)

Returns the name of the file associated with port if it is a file port, #f otherwise.

(port-line-number)

Returns the current line number of a file input port or string input port, i.e. the number of newline characters that have been read from this port plus one. ``Unreading'' a newline character decrements the line number, but it never drops below one. The result of applying port-line-number to an output port is undefined.

(tilde-expand file)

If file starts with a tilde, performs tilde expansion as described above and returns the result of the expansion (a string); returns file otherwise. file is a string or a symbol.

(file-exists? file)

Returns #t if file is accessible, #f otherwise. file is a string or a symbol; tilde expansion is not performed.


Markup created by unroff 1.0,    September 24, 1996,    net@informatik.uni-bremen.de