Mercurial > repos > other > SevenLanguagesInSevenWeeks
diff 3-Prolog/day1-self-study.pl @ 61:49cb2f7af872
Fix the Day 1 collaboration problems
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Fri, 29 Sep 2017 20:00:50 +0100 |
parents | c9873b78e8c2 |
children | 96e77f914f9b |
line wrap: on
line diff
--- a/3-Prolog/day1-self-study.pl Wed Sep 27 20:48:28 2017 +0100 +++ b/3-Prolog/day1-self-study.pl Fri Sep 29 20:00:50 2017 +0100 @@ -21,8 +21,8 @@ wrote(jack_yeovil, route_666). wrote(jack_yeovil, krokodil_tears). -collaborated(Author1, Author2, Book) :- \+(Author1 = Author2), author(Author1), author(Author2), - wrote(Author1, Book), wrote(Author2, Book), book(Book). +collaborated(Author1, Author2, Book) :- author(Author1), author(Author2), + wrote(Author1, Book), wrote(Author2, Book), book(Book), Author1 \== Author2. collaborated(Author1, Author2) :- collaborated(Author1, Author2, Book). % collaborated(terry_pratchett, stephen_baxter). returns true, but collaborated(Author1, Author2). just says "no", as does @@ -35,4 +35,10 @@ % wrote(terry_pratchett, Book). works to return all books by an author, though. % % However, having added a three-argument version, it can correctly identify the books that someone collaborated on if -% you supply both authors but it won't supply an author when given one author and the book title. \ No newline at end of file +% you supply both authors but it won't supply an author when given one author and the book title. +% +% On tracing this and the W&G example then it seems that "\+(…)" doesn't play nicely with variables. The W&G examples +% worked because we only asked "are these two people friends" questions, not "who is friends with" questions. +% +% What we actually need is "\==" (not equal/equivalent). Also, we need to put it at the end so that Author1 and Author2 have +% been assigned by that point. \ No newline at end of file