SWI-Prolog FAQ

This FAQ is designed specifically for Lehigh students taking CSE 327. If you don't find the answer to your question here, you may also want to try the official SWI-Prolog FAQ.

Table of Contents

  1. How do I install SWI-Prolog on a PC in a Lehigh Public Site?
  2. How do I install SWI-Prolog on my personal computer?
  3. In class you showed us a special editor that colorizes the Prolog program. How do I use this editor?
  4. What does the "clauses are not together in the source-file" error mean?
  5. What does the "Singleton variables" warning mean, and how can I fix it?
  6. My program appears to be stuck in an infinite loop. How do I stop it?
  7. Whenever I try to "Reload modified files", I get the error: "ERROR: open/3: No permission to open source_sink `INDEX.pl' (Permission denied)"

  1. How do I install SWI-Prolog on a Windows PC in a Lehigh Public Site?

    If you are in a public Lehigh computer lab, first check to see if SWI-Prolog is already installed by clicking "Start" and "All Programs". If you see the program in the list, then you do not need to do anything else but select it in order to run it. If it is missing, you can do a standard Lehigh network installation. If you have the standard Lehigh background screen, then you can simply click "Install Software". Otherwise, go to the Start menu, select "All Programs", and then select "Install Software" (it should be at the top of the menu). From the list of available software, select SWI-Prolog and proceed with the install instructions. Note, if you have WIRED access from your dorm room, then this install method should also work.

  2. How do I install SWI-Prolog on my personal computer?

    If you do not have access to Lehigh's standard software installation process, you can download SWI-Prolog yourself. Go to the SWI-Prolog download page and get the stable release. Follow the installation instructions given in the download.

  3. In class you showed us a special editor that colorizes the Prolog program. How do I use this editor?

    The editor I used in class (called PCE Emacs) comes with your SWI Prolog download. However, the default install is configured to use your normal text editor (usually Notepad). In order to make PCE Emacs the default editor from SWI Prolog, do the following

    1. Select Settings -> User init file... from SWI Prolog's menu bar.
    2. The system will say that it could not find an initialization file, and ask if you want to create one. Respond yes. As a result, a file should be opened in a text editor.
    3. Find the following line in the file:
      % :- set_prolog_flag(editor, pce_emacs).
      
    4. Remove the initial "%", effectively uncommenting the line. It should look like:
      :- set_prolog_flag(editor, pce_emacs).
      
    5. Save the file and close it.
    6. Close and restart SWI Prolog. Now when you use the New or Edit menu options, PCE Emacs should be the default editor.

  4. What does the "clauses are not together in the source-file" error mean?
  5. Sometimes when you consult your Prolog code, you will see an error such as:

    Warning: (c:/program files/prolog/myprogram.pl:5):
            Clauses of mypred/2 are not together in the source-file
    % myprogram compiled 0.00 sec, 0 bytes
    

    Generally, Prolog programs are easier to read when all of the clauses with the same head are grouped together. Note, this is not required, which is why it is only a warning and not an error. To make the message go away, simply make sure all rules with the same functor in the head (i.e., left hand side) and all facts with the same functor are on consectutive lines.

  6. What does the "Singleton variables" warning mean, and how can I fix it?

    This warning indicates that you have a statement in which a variable only appears once. This lets you know that there may be a spelling mistake or that you forgot to use the variable elsewhere in the statement. However, there are cases where you simply don't care what binding the variable has. In those cases, you can make the warning go away by replacing the variable with the underscore character "_". This essentially serves as a wildcard that will match anything.

    In the following statements, Y, Z and W are all singleton variables:

    p(X,Y) :- q(X).
    s(X) :- t(X,W).
    r(Z).
    
    To may, the warnings disappear, simply change the statements to:
    p(X,_) :- q(X).
    s(X) :- t(X,_).
    r(_).
    
  7. My program appears to be stuck in an infinite loop. How do I stop it?

    Usually, CTRL+D works. If it doesn't, type CTRL-ALT-DELETE and use the Task Manager to shut down SWI-Prolog.

  8. Whenever I try to "Reload modified files", I get the error: "ERROR: open/3: No permission to open source_sink `INDEX.pl' (Permission denied)"

    This happens in Windows 7 because SWI Prolog needs administrator privileges to update an index. Simply run the SWI Prolog in administrator mode (right click on the icon and select "Run as administrator") and then select "Reload modified files." This should build the index and you can run SWI Prolog in normal mode from then on. Note, if you are in a public Lehigh lab, you will not be able to run in administrator mode; you'll just have to ignore these errors, which should not affect you ability to write and run Prolog programs.