Skip to content

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

@cobalamin

Description

@cobalamin

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions