Writing Prolog Programs: The Mechanics.

Whether you use ALS prolog, BIM prolog, GNU Prolog, SWI prolog, or most other PC based prologs, the process of writing a prolog program is the same in principle. None of these systems (at least as installed on campus) has an IDE. However with a windowing environment you don't need one to get some of the benefits. Follow these steps when writing a prolog program.

  1. Create a file containing the prolog database of facts and rules. ALS and BIM prefer that you use the extension .pro, GNU and SWI use .pl.
  2. Run a copy of your prolog so that it uses the directory in which your program file is as its working directory. The easiest way to do this is to create an icon for the executable and set the properties appropriately. You can start ALS from the command line in both Solaris and Wintel. So if your path is set right that gives you another way to have the working directory be what you want. (You can't start SWI this way.)
    GNU Prolog is in /opt/local/products/gprolog-1.0.0/bin/. Top run it make sure that this directory is on your path. You can start GNU by typing gprolog at the command line.
  3. Load your file into the prolog environment. Suppose that your file is called myprog.pro for ALS or myprog.pl for SWI. You load it into the environment by typing at the ?- prompt

    reconsult does not work in SWI. [myprog] works in ALS but has the effect of consult. Thus if you do it twice you get two copies of the file loaded not just one. (This didn't get standardized, sorry!).

    With ALS and BIM because they can be started on the command line you can load the file when you start Prolog by typing alspro myprog or BIMprolog myprog. You can create a version of GNU prolog that does this too if you want. See the documentation in /opt/local/products/gprolog-1.0.0/doc.

  4. If the program has syntax errors the Prolog environment will tell you about them. You can re-edit the file to get rid of them and then reload, as above.
  5. Now run your goals at the ?- prompt. Editing and reloading as necessary.

Where to find the Prologs

  • GNU Prolog can be found at Daniel Diaz's site
    It is also on maxwell in /opt/local/products/gprolog-1.0.0/bin/


    [GO HOME] Return to AI Home Page

    Last Changed: 17 September 1999