Prolog for PCs
- Prolog is freely available from SWI-Prolog.
- pl will be installed by default to c:\\program files\pl
Useful Prolog Tidbits
- Prolog source files typically have a suffix of .pl
- You can break a list apart using [a|b] where
a denotes the first item in the list and b denotes
the rest of the list.
- To test for inequality, use \=
- not is a built-in Prolog predicate.
- The underscore ( _ ) represents an anonymous variable.
Prolog Environment Commands
- consult('file-name').
- pwd.
- ls.
- cd(directory).
- edit.
- emacs.
- make.
- trace.
- apropos(word).
- help(word).
- halt.
Examples
11/30 Exercises (Remember to meet in EPS 254)
- Construct a Prolog genealogy database
that covers 3 generations of your family.
You may use the following facts in your database:
male(x), female(x), and
parent(x, y) where x is the parent of y.
- Define mother(X,Y).
- Define father(X,Y).
- Define grandmother(X,Y).
- Define grandfather(X,Y).
- Define allgrandparents(X). This predicate should
find and print all grandparents of X.
- Define sibling(X,Y). Make sure that a person is
not his or her own sibling!
- Define allsiblings(X). This predicate should find
and print all siblings of X.
- Define aunt(X,Y).
- Define uncle(X,Y).
- Define your own Prolog predicate that determines whether an
element is a member of a list.