NOTE: We have upgraded the prolog available on UH Unix. The executable is prolog or gprolog in the ics313 course account (gnu prolog version).
/home/21/ics313/bin/prolog
Add the following to your .cshrc file alias gprolog /home/21/ics313/bin/gprolog
Documentation and versions for other platforms are available from the free software foundation: http://www.gnu.org/software/gprolog/gprolog.html
Online GNU Prolog manual (html)
Online manual:
http://pauillac.inria.fr/~diaz/gnu-prolog/manual/
Interacting with GNU Prolog
Arithmetic operators
The previous version of prolog - cprolog, is still available at: /usr/uh/pkg/cprolog-1.5/
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 .prolog, since .pl will be used for Perl later this term.
Create an alias for it named prolog to run it as prolog [.cshrc file]
alias prolog "/home/21/ics313/bin/gprolog"
and/or modify the program name in your .emacs file to run in Gnu emacs as prolog (see below).
Type prolog at the command prompt to get it started. To load a file, type either consult('file.prlg'). or ['file.prlg']. -- don't forget the period (.) at the end of the statement (tells Prolog you are done entering your statement). Then you can type queries to check your program.
Insert the following into your ~/.emacs file
(autoload 'run-prolog "prolog" "Start a Prolog sub-process." t)
(autoload 'prolog-mode "prolog" "Major mode for editing Prolog programs." t)
(setq auto-mode-alist (append '(("\\.prlg$" . prolog-mode))
auto-mode-alist))
First start emacs and create a new file named file.prlg. Put the following fact & rule statement in
file.prlg:
% -*- 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).
At the UHUNIX command prompt, type prolog or in another emacs window, start a Prolog process with M-x run-prolog.
Then type ['file.prlg']. (again, don't
forget the period - its part of Prolog syntax).
Then you can ask the system queries about your facts &
rules.
Enter ^D (control-D) or halt. to exit. See the below example.
uhunix2:/.../ics313/logic% prolog
C-Prolog version 1.5
| ?- ['file.prlg'].
file.prlg 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 ]
uhunix2:/.../ics313/logic%
Some tutorials on Prolog are : Prolog Basics & Prolog Tutorial & Prolog Programming. You can use other Prolog compilers, but your final code must compile and run on the UNIX Prolog compiler.
?- 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.prlg').
The system to finds, reads, and compiles the file 'name. pl' looking in the standard library and then the working directory.
?- tell('name.prlg'), 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.