Skip to content

Instantly share code, notes, and snippets.

@sorenmacbeth
Created May 20, 2013 21:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sorenmacbeth/5615687 to your computer and use it in GitHub Desktop.
Save sorenmacbeth/5615687 to your computer and use it in GitHub Desktop.
(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