next up previous contents index
Next: Explicit Input and Output Up: Input and output Previous: Input and output   Contents   Index

Input and output using implicit source and destination

The package for implicit input and output destination is upwards compatible to DEC-10 and C-Prolog. The reading and writing predicates refer to resp. the current input- and output stream. Initially these streams are connected to the terminal. The current output stream is changed using tell1 or append1. The current input stream is changed using see1. The streams current value can be obtained using telling1 for output- and seeing1 for input streams. The table below shows the valid stream specifications. The reserved names user_input, user_output and user_error are for neat integration with the explicit streams.

user This reserved name refers to the terminal
user_input Input from the terminal
user_output Output to the terminal
user_error Unix error stream (output only)
Atom Name of a Unix file
pipe(Atom) Name of a Unix command

Source and destination are either a file, one of the reserved words above, or a term `pipe(Command)'. In the predicate descriptions below we will call the source/destination argument `SrcDest'. Below are some examples of source/destination specifications.

?- see(data). % Start reading from file `data'.
?- tell(user_error). % Start writing on the error stream.
?- tell(pipe(lpr)). % Start writing to the printer.

Another example of using the pipe1 construct is shown below. Note that the pipe1 construct is not part of Prolog's standard I/O repertoire.


\begin{code}
getwd(Wd) :-
seeing(Old), see(pipe(pwd)),
collect_wd(String),
...
...C\vert R]) :-
get0(C), C \== -1, !,
collect_wd(R).
collect_wd([]).
\end{code}

see1+SrcDest Make SrcDest the current input stream. If SrcDest was already opened for reading with see1 and has not been closed since, reading will be resumed. Otherwise SrcDest will be opened and the file pointer is positioned at the start of the file.

tell1+SrcDest Make SrcDest the current output stream. If SrcDest was already opened for writing with tell1 or append1 and has not been closed since, writing will be resumed. Otherwise the file is created or--when existing--truncated. See also append1.

append1+File Similar to tell1, but positions the file pointer at the end of File rather than truncating an existing file. The pipe construct is not accepted by this predicate.

seeing1?SrcDest Unify the name of the current input stream with SrcDest. telling1?SrcDest Unify the name of the current output stream with SrcDest.

seen0 Close the current input stream. The new input stream becomes user.

told0 Close the current output stream. The new output stream becomes user.


next up previous contents index
Next: Explicit Input and Output Up: Input and output Previous: Input and output   Contents   Index
Dr. Richard Botting 2001-12-12