51
|
1 % Start with some simple facts
|
|
2 % Note: like semantic systems, names are intrinsicly equal variables
|
|
3 % (or variables don't exist). Names are called "atoms"
|
|
4 likes(wallace, cheese).
|
|
5 likes(grommit, cheese).
|
|
6 likes(wendolene, sheep).
|
|
7 % Each statement ends with a fullstop
|
|
8
|
|
9 % Rule syntax is a bit odd (":-" and "\+") but we're saying that X and Y
|
|
10 % can be friends if X and Y like the same thing.
|
|
11 % Poor Wendolene.
|
|
12 friend(X, Y) :- \+(X = Y), likes(X, Z), likes(Y, Z).
|
|
13 % "\+" is apparently logical negation (because of course it is)
|
|
14 % so the first "subgoal" stops Wallace being Wallace's friend
|
|
15 %
|
|
16 % Note: Prolog nomenclature is that this is "friend/2" - friend func with 2 params |