Lecture 25 - November 20, 2007
Quiz
Prolog:
To get into the interpreter: pdprolog
<return>
To get out of the interpreter: exitsys.
All Prolog statements end with a
period. Don't forget to type it.
In LISP we had atoms and lists.
In Prolog we have facts and rules.
In LISP we used the load statement to get code into the LISP
interpreter
In Prolog we use consult('filename.pro').
to load a program in
To UNLOAD use forget('filename.pro').
Comments are inserted between /*
and */
A Prolog program consists of a
database of facts and rules.
We can see all of the predicates in
the database by typing dir p.
We can see all of the constants by
typing dir.
We can see everything that has been
typed in using listing.
Constants begin with lower case
letters.
Variables begin with upper case
letters.
FACTS are headless Horn clauses.
FACTS can have one or many arguments.
Examples:
tall(troy).
father(sam,joe).
RULES are headed Horn clauses.
RULES have an if in them.
The if is a colon hyphen pair
without a space between them.
An and
is a comma
Examples:
happy(mary)
:- tall(mary).
happy(sam)
:- tall(sam), rich(sam).
Facts and rules can be added
interactively using asserta and assertz
The problem with using asserta and assertz is that
there's no command to save the contents of your data base to disk.
Examples:
asserta(likes(john,mary)).
assertz(likes(john,paula)).
Once you have facts and rules in the
database, you can query the database.
Two sets of slides to review
Slides reviewed in
class
Slides from text
RESOLUTION and INSTANTIATION are important ideas.
Family.pro as
a text file gives us that each person is
their own sibling
Family2.pro as a text file eliminates the error
Test.pro as a text file was gone over in 2pm section.