jonase/learndatalogtoday

Chapter 8, Exercise 1: case of director & cast for the same movie not handled

Opened this issue · 1 comments

In Chapter 8, Exercise 1, the suggested solution is as follows:

[[(friends ?p1 ?p2)
  [?m :movie/cast ?p1]
  [?m :movie/cast ?p2]
  [(not= ?p1 ?p2)]]
 [(friends ?p1 ?p2) [?m :movie/cast ?p1] [?m :movie/director ?p2]]
 [(friends ?p1 ?p2) (friends ?p2 ?p1)]]

I think the second rule definition should also have an inequality clause for ?p1 and ?p2, and read

[(friends ?p1 ?p2)
  [?m :movie/cast ?p1]
  [?m :movie/director ?p2]
  [(not= ?p1 ?p1)]]

Which certainly looks more verbose and doesn't fit on the same line in the exercise editor anymore, but it handles a previously unhandled case: When a director is also cast in their own movie (which doesn't seem to exist in this db, but generally isn't that unlikely).

Perhaps I'm missing something and the first rule definition already prevents this?

You're correct. PR welcome!