Introduction
The following resources are copyright James Powers 1997
Lab is due on Wednesday 12/2 (after Thanksgiving).
0. Getting Started
- SWI Prolog for Windows opens from the start menu.
- Once open, you can consult a file (prolog terminology for opening a prolog source file) using the File::Consult menu.
- You can also enter facts and rules directly by consulting the 'user' as follows. Text in yellow is what you would type; the white characters are Prolog prompts. Note that lines need to end with periods, and in the last line, you actually hit the key sequence ctrl-d rather than typing it :-)
5 ?- [user].
|: eats(john,shrimp).
|: eats(mary,haddock).
|: <ctrl-d>
Now work through Tutorial 0
1. Facts and Rules
Rules take the following form:
friends(X,Y) :- likes(X,Z), likes(Y,Z).
This says that two people are friends if they share a common thing that they like, or literally: “prolog should conclude that X and Y are friends if there’s something (Z) that both X and Y like”
Here’s another example of a rule:
% mother(C,M) is true if C has a mother named M
mother(C,M) :- parent(C,M), female(M).
Now work through Tutorial 1
2. Some Arithmetic
Now work through Tutorial 2
After working through this section, complete the exercises at the bottom of the page.
- For exercise 2, keep in mind that Prolog uses args to state relationships, not to return values as in Scheme. Thus you will define a prolog relation with two args, the second being the result.
- For exercise 3, the relation will have 3 args.
