next up previous
Next: Writing to file Up: Files and I/O Previous: Changing I/O streams

Reading from a file

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).



Omer F Rana
Mon Mar 17 12:47:04 GMT 1997