Mercurial > repos > other > SevenLanguagesInSevenWeeks
diff 3-Prolog/readme.txt @ 58:90c4b7f28690
Add initial Day 2 notes for Prolog
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Tue, 26 Sep 2017 20:58:49 +0100 |
parents | 005ae3fad18f |
children | 05871e7ac124 |
line wrap: on
line diff
--- a/3-Prolog/readme.txt Tue Sep 26 20:47:20 2017 +0100 +++ b/3-Prolog/readme.txt Tue Sep 26 20:58:49 2017 +0100 @@ -11,4 +11,14 @@ When you ask a question with a placeholder, the placeholder has to be capitalised. Lower-case makes it an atom. When Prolog returns its answers, type ";" to get the next response or "a" to get all. Sometimes Prolog will end multiple responses with "no", sometimes with "yes". This depends on whether it needs to do more calculations to check for more answers ("no") -or whether it knows it successfully gave you everything ("yes"). \ No newline at end of file +or whether it knows it successfully gave you everything ("yes"). + +Rules don't need to be defined once. If you define the following: + +ancestor(X, Y) :- father(X, Y). +ancestor(X, Y) :- father(X, Z), ancestor(Z, Y). + +then Prolog will check both "definitions" of the rule. + +(Note: putting the recursive "ancestor/2" call at the end is called "tail recursion" and the language can optimise it to +reduce call stack exhaustion issues) \ No newline at end of file