The Prolog interpreter and compiler we use in Bangor is called SICStus Prolog, which runs under Unix. As explained in Basic Unix Commands, all Unix commands are run from a program called the SHELL, which acts as an intermediate between the user and the operating system proper. The easiest way to use the SICStus interpreter is to run it from an Emacs shell: you type the commands to a Unix prompt as usual, but you also have direct access to the entire history of commands and command output as if you were editing a file with Emacs.
To do this, start the Emacs editor, and then use the command
M-x shell.
Your usual Unix prompt will now be displayed in an Emacs buffer, and
you can use commands as usual (though not the ones that involve an
graphical interactive display).
To start the Prolog compiler, type sicstus at the prompt.
You will then see the following:
SICStus 2.1 #9: Mon Oct 17 13:15:54 BST 1994 | ?-
To exit the compiler, type halt at the | ?- prompt.
You can then either type another command at the shell prompt, go to another Emacs buffer, or exit Emacs.| ?- halt. Process prolog finished
There are several ways to load files into the interpreter.
You can use the predicate consult/1, as shown below.
| ?- consult(rdus).
[rdus].
{consulting /homedir/avk/Prolog/Nihi/rdus.pl...}
{/homedir/avk/Prolog/Nihi/rdus.pl consulted, 16 msec 1504 bytes}
yes
| ?-
Note that although the argument is given as rdus, the
interpreter loads the file rdus.pl.
.pl is the standard extension for Prolog files, and if you do
not specify an extension, the SICStus interpreter looks for a
file with that extension first (if it does not find one, it will look
for \textsc{rdu}s).
If a filename contains anything other than alphanumeric characters (i.e. letters or numbers) then it must be cited inside single quotes. Thus, if you want to make the .pl extension explicit, you must put quotes around the file name.
(This has the same effect as| ?- consult('parents.pl').
| ?- consult(parents).).
You can consult files not in the directory in which the
interpreter by providing a path specification.
This command loads the file parents.pl situated in the directory Prolog in user elu003's home directory. Finally, you can consult more than one file at the same time, by enclosing the filenames with square brackets.| ?- consult('~elu003/Prolog/parents.pl').
| ?- consult([foo,baz,'foobaz.pl']).
This command loads the files foo.pl, baz.pl and
foobaz.pl.
An alternative to using consult/1 is to specify the name of the
file(s) to be loaded inside square brackets:
the following examples:
You can have several files loaded at the same time, using rules and facts from all of them together (but see Where to Keep Your Predicates). The interpreter keeps track of what predicates are defined in which files, and unless you specify otherwise, each predicate can only be defined in one file.| ?- [parents].
| ?- ['parents.pl'].
| ?- [foo,baz].
If you edit and reconsult a file that you have already consulted, all definitions associated with the previous version of the file are removed, and the new ones are used in place. However, if you consult a file with different procedures, old procedures which are not being redefined are retained. If you wish to clear the database completely before you consult a file, you must exit SICStus and restart it before consulting.
M-x shelland then type sicstus after the unix prompt.
consult\1 at the Prolog prompt,
e.g. consult(myfile)..
listing/0 command.
halt/0 command.
<a.von.klopp@bangor.ac.uk>