Information Technology Reference
In-Depth Information
The special predicate
ls
can be used to see what files are in the current folder and are
available to be loaded:
?- ls.
blocks.pl
grid.pdf
myfamily.pl
daisy.jpg
monkey.pl
planner.pl
Yes
?- [blocks].
% blocks compiled 0.00 sec, 2,088 bytesYes
Note that
ls
lists all the files in the current folder. Only the files whose names end
with
.pl
, such as
blocks.pl
, can be loaded. It is sometimes necessary to load two or
more files, which can be done as follows:
?- [planner,monkey].
% planner compiled 0.00 sec, 1,432 bytes
% monkey compiled 0.00 sec, 2,012 bytes
Yes
The next thing to worry about is that Prolog finds your file but cannot load it without
an error:
?- [myfamily].
ERROR: myfamily.pl:4:0: Syntax error: Operator expected
% myfamily compiled 0.00 sec, 1,400 bytes
Yes
This error means that
myfamily.pl
is not yet a legal Prolog program. Typically,
punctuation of some sort is wrong. Here is a listing of the
myfamily.pl
file:
child(henry,hanna).
male(henry)
female(hanna).
mother(X,Y) :- child(Y,X), female(Y).
As can be seen, there is a missing period at the end of the second clause. Prolog
reports where it runs into trouble. The
myfamily.pl:4:0
on the error line means that
it was at line 4 column 0. (The actual error is typically somewhere nearby. It is a good
idea to use a text editor like Notepad or TextEdit that allows you to easily get to a
line in a file by its line number.)
Here is what you need to do: Go to the text editor window, find the grammatical
error, change the file, and save the new version of the file. Then go back to the Prolog
window, and use the special predicate
make
to reload the file into Prolog: