Skip to content

Latest commit

 

History

History
63 lines (46 loc) · 1.71 KB

2020-07-04.md

File metadata and controls

63 lines (46 loc) · 1.71 KB

Learning Clojure in Public - Week 2 Day 6 (13/35)

Expectations

Little to no expectations, after all it's a holiday! (and I didn't even post this update on time)

What I learned

Learn Datalog Today Chapter 7

Exercise 0: count the number of movies in the database

[:find (count ?movie)
 :where
 [?movie :movie/title]]

Exercise 1: Find the birth date of the oldest person in the database.

[:find (min ?date)
 :where
 [_ :person/born ?date]]

Exercise 2: Given a collection of actors and (the now familiar) ratings data. Find the average rating for each actor. The query should return the actor name and the avg rating.

[:find ?name (avg ?rating)
 :in $ [?name ...] [[?title ?rating]]
 :where
 [?p :person/name ?name]
 [?m :movie/title ?title]
 [?m :movie/cast ?p]]

Chapter 8

Exercise 0: Write a rule [movie-year ?title ?year] where ?title is the title of some movie and ?year is that movies release year.

[[(movie-year ?title ?year)
  [?m :movie/year ?year]
  [?m :movie/title ?title]]]

Exercise 1: Two people are friends if they have worked together in a movie. Write a rule [friends ?p1 ?p2] where p1 and p2 are person entities. Try with a few different ?name inputs to make sure you got it right. There might be some edge cases here.

[[(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]]]

Takeaways

I am glad I finished Learn Datalog Today, the last two chapters were more difficult that the previous ones, took longer than expected. If the $25 are not claimed, I'll donate the rest to a charity.