Mercurial > repos > other > SevenLanguagesInSevenWeeks
comparison 3-Prolog/day1-wallaceandgrommit.pl @ 51:178b18b4f9ba
Start experimenting with Prolog
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Mon, 25 Sep 2017 20:49:52 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
50:b94161b72db6 | 51:178b18b4f9ba |
---|---|
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 |