Project "Contraintes" Prolog Web Pages: IO in standard Prolog.

A major change in the Prolog language that is aprt of the standard was the introduction of a completely new set of predicates for input and output. In the standard these replace the see and tell predicates of Edinburgh Prolog. This page summarises the new predicates. A more detailed description of the I/O predicates is available with these pages.

Streams

The new I/O predicates introduce the notion of a stream. Streams are associated by a call to the open/4 predicate. sources (sinks) from (to) which IO is done. Streams can be identified either by a stream-term which is an implementation dependent ground term created as a result of a call to open/4 or by use of an alias which is assigned by the call to open/4.

Input/Output Modes

An input/output mode is an atom which defines in a call of open/4 the operations that may be performed on a source/sink. The required modes, which have the obvious meanings are:

Two streams are predefined and open during the execution of any goal:

At any time there is a current input stream and a current output stream, by default these are initially the standard input stream and the standard output stream respectively. Predicates are provided for changing the current input or output stream.

The standard makes a distinction between text streams and binary streams, with distinct predicates for

Stream Positioning

For somke implementations it may be possible to set the position on a source/sink. Whether this is possbile for a given stream is determined by the call to open/4 and whether the appropriate stream option is set. A standard conforming program shall make no assumptions about the form of a stream position term except thst it is ground and uniquely identifies a position in the stream. At the end of a stream a specific value shall be returned to indicate that the end of the stream has been reached. The terms indicating end-of-stream and past-end-of-stream shall be implemenetation defined.

Options on Stream Creation

When a strem is opened using open/4 the fourth argument specifies a list of options for the stream so created. The following options are requied by the standard.
type(T)
Specifies whether the stream is a text stream or a binary stream: T may be: The default is text.
reposition(Boolean)
If Boolean is true then it shall be possible to reposition the stream, else if it is false it is implementation defined whether it is possible to reposition.
alias(A)
Specifies that the atom A shall be an alias for the stream.
eof_action(Action)
This determines the effect of attempting to input form a stream whose stream position is past-end-of-stream. The required values for Action are: It is implementation defined which Action is the default.

Options on Stream Closure

A close option modifies the effect of close/2 if an error condition occurs while attempting to close a stream. The required options are:

Stream Properties

The properties of a stream can be discovered using the predicate stream_property(Stream, Property). The stream properties shall include:

Read-Options List

A read-options list is a list of options which affects the behaviour of read_term/3. The read options shall include

Write-Options List

A write-options list affects write_term/3. These shall include: Many prologs contain a predicate numbervars/3 that causes variables appearing in terms to be converted to this special form. Live examples of the write options.


Return to Home Page of the INRIA ISO Prolog Web

Author: J.P.E. Hodgson
Saint Joseph's University
Philadelphia PA 19131
USA


Last Changed: 1 janvier 2003