A Tutoring Lab

for Logic Programming and Artificial Intelligence

Table of Contents

  1. How do I write a Prolog program and execute it ?
  2. Where can I find a Prolog interpreter?
  3. Why special symbols do not appear in the screen ?
  4. What is 'Warning: singleton variable' ?
  5. What do I do if I get 'Action (h for help)' ?

How do I write a Prolog program and execute it ?

Create a directory in your hard disk (e.g. C:\MyPrologPrograms). You can write your Prolog program in any text editor (e.g. notepad). If you are using SWI-Prolog, save it with an extension ".pl" in the directory with your programs, so that it can be recognised as a SWI-Prolog program. Leave the editor open. You may need it.

Click on SWI-Prolog icon. You are prompt with a "?-". Make sure you are working in the appropriate directory (where your program is stored). Type "?-pwd." to get the name of the current directory. If it is different from the one you need then type for example "?-cd('C:\MyPrologPrograms')." If you type "?-ls." you are going to get a list of files contained in this directory.

In order to load the file into the Prolog interpreter use consult/1 and type the name of the file, for example "?-consult(test)" if test has an extention .pl or the complete filename included in single quotes. Alternatively, you could use "?-[test].". Now you can pose any query.
 

Back to Top

Where can I find a PROLOG interpreter ?

You can download a PROLOG interpreter to be used for running the programs that you will need to implement. We recommend that you download SWI-PROLOG from the site:
http://www.swi.psy.uva.nl/usr/jan/SWI-Prolog.html
In there you will find installation instructions. Installing it is quite straightforward. In case you have any other PROLOG available please contact us to discuss compatibility issues.
Back to Top

Why special symbols do not appear on the screen ?

The easiest way to get around it is to set the option "Use document specified fonts" in the Preferences/Fonts option, if you are using Netscape Navigator.
Back to Top

What is "Warning: Singleton Variable" ?

It is just a warning you get from the SWI-interpreter. Singleton is a variable that appears only once in a program clause and therefore there is no reason to have a name (it could have been anonymous "_" instead). However, you are prompt with this warning because you might  have mispelled the name of the variable. For example:
    father(Father,Child):- parent(Father,Child), male(Fathr).
In the above, Fathr is a singleton variable.
Back to Top

What do I do if I get "Action (h for help)" ?

Well, you type "h" to get a menu for possible actions. Normally, you type "a" for aborting the execution and get back to the "?-". In any case to abort execution type "Ctrl-C".
Back to Top

P.Kefalas.
Copyright © [TEI Thessaloniki]. All rights reserved.
Revised: 12/3/99.