Next: Reading Characters
Up: Files and I/O
Previous: Reading from a file
- Assign current output stream to file name
- Done via the tell(Filename) command
- If ANY file already opened for writing
- tell will write to that file
- told closes the file and switches output
stream back to default value - the user
- In MacProlog also have seeing/0 - which
returns the current input stream - (file currently opened)
copy(Filename) :-
tell(user),
write( 'Term: '),
read(Term),
tell(Filename),
perform(Term, Filename).
perform( stop,_) :- told.
perform( Term, Filename) :-
write(Term), nl,
copy(Filename).
- If arguments of tell not instantiated,
tell(Filename) fails
- If argument instantiated to a filename that does not
exist, a new file of that name is created and output
stream switched
- Over writes an existing file
Omer F Rana
Mon Mar 17 12:47:04 GMT 1997