annotate 3-Prolog/day1-wallaceandgrommit.pl @ 73:74976fddd25f

Ignore Erlang binary files and remove existing ones
author IBBoard <dev@ibboard.co.uk>
date Sat, 03 Feb 2018 19:52:45 +0000
parents 178b18b4f9ba
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
51
178b18b4f9ba Start experimenting with Prolog
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 % Start with some simple facts
178b18b4f9ba Start experimenting with Prolog
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 % Note: like semantic systems, names are intrinsicly equal variables
178b18b4f9ba Start experimenting with Prolog
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
3 % (or variables don't exist). Names are called "atoms"
178b18b4f9ba Start experimenting with Prolog
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4 likes(wallace, cheese).
178b18b4f9ba Start experimenting with Prolog
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 likes(grommit, cheese).
178b18b4f9ba Start experimenting with Prolog
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 likes(wendolene, sheep).
178b18b4f9ba Start experimenting with Prolog
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 % Each statement ends with a fullstop
178b18b4f9ba Start experimenting with Prolog
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8
178b18b4f9ba Start experimenting with Prolog
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 % Rule syntax is a bit odd (":-" and "\+") but we're saying that X and Y
178b18b4f9ba Start experimenting with Prolog
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 % can be friends if X and Y like the same thing.
178b18b4f9ba Start experimenting with Prolog
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 % Poor Wendolene.
178b18b4f9ba Start experimenting with Prolog
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 friend(X, Y) :- \+(X = Y), likes(X, Z), likes(Y, Z).
178b18b4f9ba Start experimenting with Prolog
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 % "\+" is apparently logical negation (because of course it is)
178b18b4f9ba Start experimenting with Prolog
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 % so the first "subgoal" stops Wallace being Wallace's friend
178b18b4f9ba Start experimenting with Prolog
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 %
178b18b4f9ba Start experimenting with Prolog
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 % Note: Prolog nomenclature is that this is "friend/2" - friend func with 2 params