03.06.2013 Views

Turbo Prolog

Turbo Prolog

Turbo Prolog

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

To access a file, it must first be opened. A file can be opened in four ways:<br />

• For reading<br />

• For writing<br />

• For appending to the file<br />

• For modification<br />

A file opened for any activity other than reading must be closed when that activity is<br />

finished or the changes to the file will be lost. Several files may be open simultaneously,<br />

and input and output can be quickly redirected between open files. In contrast, it takes<br />

longer to open and close a file than to redirect data between files.<br />

When a file is opened, <strong>Turbo</strong> <strong>Prolog</strong> connects a symbolic name to the actual name of<br />

the file used by DOS. This symbolic name is used by <strong>Turbo</strong> <strong>Prolog</strong> when input and<br />

output are redirected. Symbolic file names must start with a lowercase letter and must<br />

be declared in the file domain declaration:<br />

file = fileL ; source ; auxiliary<br />

Only one file domain is allowed in any program, and the four symbols<br />

printer<br />

screen<br />

keyboard<br />

comL<br />

are automatically defined in advance in the file domain and must not appear in the file<br />

declaration. printer refers to the parallel printer port and com I refers to the serial<br />

communication port.<br />

Following are the standard predicates for opening and closing files.<br />

openread{SyrnbolicFileNarne,DosFileNarne)<br />

The file DosFileName is opened for reading. The file is then referred to by the symbolic<br />

name SymbolicFileName. If the file is not found, the predicate fails. If DosFileName is<br />

illegal, an error message is displayed.<br />

openwrite{SyrnbolicFileNarne,DosFileNarne)<br />

The file DosFileName is opened for writing. If the file already exists, it is deleted. Otherwise,<br />

the file is created and an entry made in the appropriate DOS directory.<br />

openappend{SyrnbolicFileNarne,DosFileNarne)<br />

The file DosFileName is opened for appending. If the file is not found, an error message<br />

is displayed and execution halted.<br />

openrnodify{SyrnbolicFileNarne,DosFileNarne)<br />

The file DosFileName is opened for both reading and writing. openmodify can be used in<br />

conjunction with the (ilepos standard predicate (see page 102) to update a random<br />

access file.<br />

]00 <strong>Turbo</strong> <strong>Prolog</strong> Owner's Handbook

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!