Skip to content

Instantly share code, notes, and snippets.

@rodnaph
Last active December 12, 2015 04:48
Show Gist options
  • Save rodnaph/4716586 to your computer and use it in GitHub Desktop.
Save rodnaph/4716586 to your computer and use it in GitHub Desktop.
(defn nullo
[x]
(== '() x))
(defn pairo
[x]
(fresh [a b]
(conso a b x)))
(defn flatteno
"Relation where out is a flattened s"
[s out]
(conde
((nullo s) (== () out))
((pairo s)
(fresh [a d res-a res-d]
(conso a d s)
(flatteno a res-a)
(flatteno d res-d)
(appendo res-a res-d out)))
((conso s () out))))
(run 1 [q]
(flatteno [1 [2 3] [4]] q)) => (([1 [2 3] [4]]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment