Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
(comment
(defrel edge a b)
(def graph [{:id :gen :in [] :out ["a" "b"]}
{:id :plus :in ["a"] :out ["plus"]}
{:id :times :in ["plus"] :out ["times"]}])
(fact edge '{:id :gen :in [] :out ["a" "b"]} '{:id :plus :in ["a"] :out ["plus"]})
(fact edge '{:id :plus :in ["a"] :out ["plus"]} '{:id :times in ["plus"] :out ["times"]})
(defn get-out-fields [x]
(:out x))
(defn get-in-fields [x]
(:in x))
(defne ancestorso
"y is all ancestors of x"
[x y]
([x y]
(edge y x))
([x y]
(fresh [z]
(edge z x)
(ancestorso z y))))
(defne descendantso
"y is all descendants of x"
[x y]
([x y]
(edge x y))
([x y]
(fresh [z]
(edge x z)
(descendantso z y))))
(defn siblingso
"y is all siblings (common parent) of x"
[x y]
(fresh [z]
(edge z x)
(edge z y)
(!= x y)))
(defn common-ancestoro
"r is all common acenstors of x and y"
[x y r]
(ancestorso x r)
(ancestorso y r))
(run* [q]
(siblingso q {:id :plus :in ["a"] :out ["plus"]}))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment