Next: Writing to file
Up: Files and I/O
Previous: Changing I/O streams
see('data.txt')
opens the file for reading. To switch back to the
default input stream (i.e. the user, instead of a file), use
the command seen.
display(Filename) :-
see(Filename),
read(Term),
write(Term), nl,
see(user),
write('More terms: (y/n)'),
read( Yes_No),
perform( Yes_No, Filename).
perform( n,_).
perform( _,Filename) :-
display( Filename).
- The goal : see(Filename) succeeds only once, and cannot
be re-satisfied on backtracking
- The first time it is satisfied for some file, that file
- Filename is opened
- Reading of terms from file, in a top down manner, until
seen is encountered
- If Filename is not instantiated or does not exist -
then goal fails
Omer F Rana
Mon Mar 17 12:47:04 GMT 1997