Files and Input/Output Streams

A file is referred to by its name, written as an atom, eg.

Unless directed otherwise , input or output refer to standard input and standard output. When the terminal is waiting for input on a new line, the prompt ':' is displayed.

Streams are a special type of term. They may be created either directly, (by calls to open or process) or indirectly (by calls to see and tell) and may refer to a file or to the user's terminal. Each stream is either for input or output, not both.

There is a limit of twenty input/output streams that can be open at any one time. Three of these streams are reserved for standard input, standard output and error output .These reserved streams are identified by the atoms user_input, user_output and user_error respectively. Normally, they refer to your terminal, but may be redirected in the usual way in Unix by using '<' and '>' in the shell command.

All I/O errors (including trying to use a stream previously closed) cause a failure of the procedure and warnings are issued on the standard error file.

At end of file, the built-in predicate eof becomes true. Any more input requests for a file whose end has been reached causes Prolog to return the atom end_of_file.

When the current output stream is closed, standard output becomes the current output stream. Similarly, when the current input stream is closed, standard input becomes the new input stream.

Streams may be passed as the first argument to most input/ouput predicates. For example:

prints the atom 'word' on the output stream `Stream'.

However, output to a stream does not necessarily get sent immediately due to it being buffered. A stream may be flushed by using the predicate flush_output. (The standard error stream is usually unbuffered)

BUILT-IN PREDICATES

Streams

load

unload

file

pp

listing

see

seeing

seen

tell

telling

told

eof

read

ratom

[...]

ask

print

prin

write

nl

getc

skip

putc

ascii

tab