By default, SWI-Prolog is installed as `swipl'. The command-line arguments of SWI-Prolog itself and its utility programs are documented using standard Unix man pages. SWI-Prolog is normally operated as an interactive application simply by starting the program:
machine% swipl Welcome to SWI-Prolog ... ... 1 ?-
After starting Prolog, one normally loads a program into it using
consult/1,
which may be abbreviated by putting the name of the program file between
square brackets. The following goal loads the file
likes.pl
containing clauses for the predicates likes/2 :
?- [likes]. % likes compiled, 0.00 sec, 17 clauses true. ?-
After this point, Unix and Windows users unite, so if you are using Unix please continue at section 2.1.2.
After SWI-Prolog has been installed on a Windows system, the following important new things are available to the user:
swipl
containing the executables,
libraries, etc. of the system. No files are installed outside this
directory.
.pl
is associated with the program
swipl-win.exe. Opening a .pl
file will cause
swipl-win.exe to start, change directory to the directory in
which the file-to-open resides and load this file.
The normal way to start with the likes.pl
file mentioned
in
section 2.1.1.1 is by simply
double-clicking this file in the Windows explorer.
After loading a program, one can ask Prolog queries about the program. The query below asks Prolog what food `sam' likes. The system responds with X = <value> if it can prove the goal for a certain X. The user can type the semi-colon (;) or spacebar6On most installations, single-character commands are executed without waiting for the RETURN key. if (s)he wants another solution. Use the return key if you do not want to see the more answers. Prolog completes the output a full stop (.) if the user uses the return key or Prolog knowns there are no more answers. If Prolog cannot find (more) answers, it writes false. Finally, Prolog can answer using an error message to indicate the query or program contains an error.
?- likes(sam, X). X = dahl ; X = tandoori ; ... X = chips. ?-
Note that the answer written by Prolog is a valid Prolog program that, when executed, produces the same set of answers as the original program.7The SWI-Prolog toplevel differs in several ways from traditional Prolog toplevel. The current toplevel was designed in cooperation with Ulrich Neumerkel.