Created
January 28, 2013 00:57
-
-
Save hiredman/4651836 to your computer and use it in GitHub Desktop.
treeo
This file contains 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
(defn treeo | |
"relation for trees represented as maps a la | |
clojure.xml/parse. `children` is the key of the map where children | |
are. `root` is the root of the tree, can be a logic var. `m` is a | |
map to \"pattern match\" against." | |
[children root m] | |
(if (map? m) | |
(if-let [x (get m children)] | |
(if (coll? x) | |
(logic/conde | |
[(logic/fresh [content] | |
(logic/featurec root (assoc m children content)) | |
(logic/everyg (fn [element] | |
(logic/fresh [new-root] | |
(logic/membero new-root content) | |
(treeo children new-root element))) | |
x))] | |
[(logic/fresh [x y] | |
(logic/featurec root {children x}) | |
(logic/membero y x) | |
(treeo children y m))])) | |
(logic/featurec root m)) | |
(logic/== root m))) | |
(def xmlo (partial treeo :content)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment