# HG changeset patch # User IBBoard # Date 1506711650 -3600 # Node ID 49cb2f7af872d1cd6dd152275c75d6b113af71a4 # Parent 643eec1f9e3a4e09a1b46cdfbf6275c7c8b84688 Fix the Day 1 collaboration problems diff -r 643eec1f9e3a -r 49cb2f7af872 3-Prolog/day1-self-study.pl --- 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