Prolog Resources
How to Run Prolog Programs
Download your own copy of the Prolog compiler from the SWI-Prolog Home Page. The free software is available for UNIX, Linux, MS-Windows, and MacOS. Use any text editor to write or view Prolog source code. Save a Prolog program in a file with extension '.pl'. To run SWI-Prolog in Solaris, type 'pl'. To run SWI-Prolog in Windows, start 'plwin.exe' or double-click the Prolog file in Explorer.
Here are some Prolog commands that can be typed after the '?-' prompt.
consult(filename). | This statement loads the Prolog clauses from a file if the filename has no embedded punctuation. The suffix '.pl' is added automatically, if needed. |
consult(‘filename.example’). | This statement has to be used for loading the Prolog clauses from a file if the filename has embedded punctuation. |
listing. | List the current database contents. |
trace. | Turn to debug tracing (CALL/EXIT/FAIL/REDO). |
abort. | Abort execution. |
halt. | Exit this Prolog session. |
A final period is used to terminate a command. If you forget the period, then Prolog gives you a cryptic prompt such as '|:', to indicate that you should complete your command, which is continuing from the previous line.
A variable is written as a sequence of letters and digits, beginning with a capital letter. The underscore ( _ ) is considered to be a capital letter. Examples: X, Max, _This, ThatNode.
An atom is any sequence of letters and digits, beginning with a lowercase letter. Alternatively, an atom is any sequence of characters, enclosed by single quotes ('); an internal single quote must be doubled. Examples: cat, r124c41, max_value, maxValue, 'Peter'.
Prolog Tutorials
Learn Prolog Now! Good for beginners.
Excellent prolog :- tutorial by J.R. Fisher with many sample programs.
Don't hesitate to send an email to kaufmann at ifi.unizh.ch before wasting a lot of time with Prolog problems.