Skip to content

Instantly share code, notes, and snippets.

@nathanmarz
Created August 27, 2010 01:43
Show Gist options
  • Save nathanmarz/552615 to your computer and use it in GitHub Desktop.
Save nathanmarz/552615 to your computer and use it in GitHub Desktop.
(def average
(<- [!val :> !avg])
(c/count !count)
(c/sum !val :> !sum)
(div !sum !count :> !avg))
(defn people-older-than [threshold]
(<- [?person]
(age ?person ?age)
(> ?age threshold)))
(defn old-male-people [male-people]
(<- [?person]
(male-people ?person)
(age ?person ?age)
(> ?age 90)))
(<- [?avg-age]
(age _ ?age)
(average ?age :> ?avg-age))
;; Find everyone who is 25 years old
"SELECT person FROM Age WHERE age = 25"
(<- [?person] (Age ?person 25))
;; Find all the male people that Emily follows
"SELECT F.target AS person FROM Follows F, Gender G WHERE F.source = "Emily" AND G.gender = "m" AND F.target = G.person"
(<- [?person] (Follows "Emily" ?person) (Gender ?person "m"))
;; Find how many people each person follows
"SELECT source AS person, COUNT(*) AS followscount FROM Follows GROUP BY source"
(<- [?person ?count] (Follows ?person _) (c/count ?count))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment