Prolog on uhunix

Using Prolog at UH on UHunix, a PC or Mac

CProlog

An early (and limited) version of prolog - cprolog, is available on UHUnix at: /usr/uh/pkg/cprolog-1.5/
The manual for cprolog is cprolog (pdf)
Note that C prolog is not a full implementation, and does not have many of the built-in functions that other interpreters have.
You may NEED to load frequent.pro in order to run some of the example prolog files.
To check, look at the output/transcript files for the prolog programs. They should show which version of Prolog was loaded and used.
"frequent.pro" contains additional functions that are in other implementations.

Add the following to your .cshrc file to use this version:
alias cprolog /usr/uh/pkg/cprolog-1.5/prolog

NOTE: We will use the file extensions .prlg or .pro, since .pl is commonly used for Perl.

Creating a new prolog file

First start emacs and create a new file named file.pro. Put the following fact & rule statement in file.pro:

% -*- Mode: Prolog -*- { Put the header file here}
father(bill, chelsea).
mother(hillary, chelsea).
parent(X, Y) :- father(X, Y).
parent(X, Y) :- mother(X, Y).

uhunix:/.../ics313/logic% prolog
C-Prolog version 1.5
| ?- ['file.pro'].
file.pro consulted 288 bytes 1.86265e-09 sec.

yes
| ?- parent(bill, chelsea).

yes
| ?- parent(chelsea, hillary).

no
| ?- mother(hillary, chelsea).

yes
| ?- parent(hillary, chelsea).

yes
| ?- ^D
[ Prolog execution halted ]
uhunix:/.../ics313/logic%  

GProlog

NEW NOTE (May 2010): Since the transition from UHUnix2 to UHUnix, the gprolog on UHunix no longer works.

Documentation and versions for other platforms are available from the free software foundation: http://www.gnu.org/software/gprolog/gprolog.html

Download and install gprolog on your machine.

SWI Prolog

http://www.swi-prolog.org/

Learn Prolog Now website . This website uses SWI prolog.

Other Prolog Implementations

Getting Started

Start the prolog of your choice from the command prompt or icon.

Once Prolog has started, to load a file, use consult to load a file with prolog statements.
consult('file.pro'). or ['file.prlg'].
Don't forget the period (.) at the end of the statement. The period tells Prolog you are done entering your statement. You should get a message that the file successfully loaded. If there are syntax errors, they will be detected when you load the file.

Once your file is loaded, you can type queries to check your program.

  • Include the lines in the Header lines for your Prolog programs. This helps your editor identify the file.

    Examples

  • For examples of Prolog functions, see frequent.pro [needed in cprolog, may give an error in other versions] monkey.pro, a cryptarithmetic puzzle crptarth.pro, or borders.pro

    Some tutorials on Prolog are : Learn Prolog Now

    Top level prolog commands

    Note: some commands are different in different interpreters.

    To exit from Prolog either input CTRL/D or the halt query:

    ?- halt.
    
    To look at the loaded program/database:
    ?- listing.
    
    To look at a definition in database/program of name:
    ?- listing(name).
    
    To ask for help:
    ?- help.
    ?- help(name).
    
    To look for help on a topic word:
    ?- apropos(word).
    
    To load a program from a file, give the query:
    ?- consult('name.pro').
    
    The system to finds, reads, and compiles the file 'name. pl' looking in the standard library and then the working directory.
    To save the current data base in file name.pro:
    ?- tell('name.pro'), listing, told.
    
    Edit a set of definitions of a term:
    ?- ed(term).
    
    You can add new rules or facts to the program/database:
    ?- assert( rule ).
    
    For example:
    ?- assert( event(8, mar, 'Prolog lab')).
    
    places a new fact in the data base.
  • Back to the Course homepage

    (c) N. E. Reed, 2005-2011