files, tell, telling, told, see, seeing, seen, append/1
When one writes a Prolog program, usually the facts and rules of the program are stored in a (text) file, and then loaded into the Prolog interpreter. Files have other uses in Prolog, too.

For example, we may wish to write out a table of results that have been computed for us by our Prolog program. One can use built-in predicates like write, nl, putc, tab and others to write out the table, but by default it will appear on the computer screen. To direct this output to a file, we use the tell built-in predicate. Suppose that we wish to write the table to a file called "mytable.data". By executing the (pseudo-)goal tell("mytable.data"), we tell Prolog that the new current output stream is to be the file "mytable.data". Subsequent writes will go to this file. When one wishes to stop writing to the file and resume writing on the screen, one uses the built-in predicate told (with no arguments). Also, the query ?- telling(X). binds X to the name of the current output file. If the current output stream is not a file, then X will be bound to something that indicates that the current output stream is the screen - for example, in Unix, X may be bound to the atom stdout (standard output, which is normally the screen). Example:

?- tell('mytable.data'), write('***** Table of results *****'), nl, told.
% the file mytable.data should now contain a single line of text as above

The built-in Prolog predicate append/1 is like tell, except that it arranges for subsequent write operations to add data to the end of the specified file, rather than overwriting the file with the first subsequent write operation. If myotherfile.dat initially contains, say, a single line, This is the first line, then append/1 works as follows:

?- append('myotherfile.dat'), write('Here is another line'), nl.
true.
?- halt.
% cat myotherfile.dat # - # is Unix comment char, cat lists file contents
This is the first line
Here is another line
%

The situation for reading from a file is analogous to writing (except that there is no analogue for append/1). One can use built-in predicates like read, getc and others to read, by default from the keyboard. By executing the (pseudo-)goal see('mydata.text'), we tell Prolog that the new current input stream is to be the file mydata.text. Subsequent reads will come from this file. When one wishes to stop reading from the file and resume reading from the keyboard, one uses the built-in predicate seen (with no arguments). Also, the query ?- seeing(X). binds X to the name of the current input file. If the current input stream is not a file, then X will be bound to something that indicates that the current output stream is the screen - for example, in Unix, X may be bound to the atom stdin (standard input, which is normally the keyboard). Example:

?- see('mydata.text'), read(X), seen, write(X), nl.
% the first Prolog term in the file mydata.text should now appear
% on the screen, having been read from the file with read(X), and then
% written to the screen with write(X) and nl.

What happens if you try to read from a file and there is nothing (left) to read, either because the file is empty, or you have previously read everything there was to read in this file? In this case, Prolog binds the variable that was the argument to read to the special atom end_of_file. Knowing this means that you can test after a read to make sure that you did not hit end of file. Example:

?- see('empty.dat'), read(Term).
Term = end_of_file 

See also current input stream, current output stream, input, output. append/3 is unrelated to append/1.