Mercurial > repos > other > SevenLanguagesInSevenWeeks
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/3-Prolog/day1-wallaceandgrommit.pl Mon Sep 25 20:49:52 2017 +0100 @@ -0,0 +1,16 @@ +% Start with some simple facts +% Note: like semantic systems, names are intrinsicly equal variables +% (or variables don't exist). Names are called "atoms" +likes(wallace, cheese). +likes(grommit, cheese). +likes(wendolene, sheep). +% Each statement ends with a fullstop + +% Rule syntax is a bit odd (":-" and "\+") but we're saying that X and Y +% can be friends if X and Y like the same thing. +% Poor Wendolene. +friend(X, Y) :- \+(X = Y), likes(X, Z), likes(Y, Z). +% "\+" is apparently logical negation (because of course it is) +% so the first "subgoal" stops Wallace being Wallace's friend +% +% Note: Prolog nomenclature is that this is "friend/2" - friend func with 2 params \ No newline at end of file