Created
May 20, 2013 21:21
-
-
Save sorenmacbeth/5615687 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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