Reading-in Programs

KEY A program is made up of a sequence of clauses, possibly interspersed with directives to the interpreter. The clauses of a procedure do not have to be immediately consecutive, but remember that their relative order may be important. To input a program from a file file, give the directive: | ?- [file]. which will instruct the interpreter to read-in (or consult) the program. The file specification file must be a Prolog atom. It may be any EMAS file name, note that if this file name contains characters which are not normally allowed in an atom then it is necessary to surround the whole file specification with single quotes (since quoted atoms can include any character); e.g. | ?- ['ecmi25.greeks']. The specified file is then read in. Clauses in the file are stored in the database ready to be executed, while any directives are obeyed as they are encountered. When the end of the file is found, the interpreter displays on the terminal the time spent for read-in and the number of bytes occupied by the program. In general, this directive can be any list of filenames, such as: | ?- [myprogram,extras,testbits]. In this case all three files would be consulted. If a filename is preceded by a minus sign, as in: | ?- [-testbits,-moreideas]. then that file is reconsulted. The difference between consulting and reconsulting is important, and works as follows: if a file is consulted then all the clauses in the file are simply added to Prolog's database. If you consult the same file twice then you will get two copies of all the clauses. However, if a file is reconsulted then the clauses for all the procedures in the file will replace any existing clauses for those procedures, i.e any such previously existing clauses in the database get thrown away. reconsult is useful for telling Prolog about corrections in your program (see the 'redo' predicate in section 1.5). Clauses may also be typed in directly at the terminal. To enter clauses at the terminal, you must give the directive: | ?- [user]. The interpreter is now in a state where it expects input of clauses or directives. To return to interpreter top level, type ^Y (Control Y). This is equivalent to an end of file for the ersatz file 'user'. However, this is only recommended if the clauses will not be needed permanently, and are few in number. For significant bits of program you should use an editor to produce an Emas file containing the text of the program. See the next section for some useful Prolog predicates that help you to do this.