Created
May 19, 2011 12:37
-
-
Save swannodette/980642 to your computer and use it in GitHub Desktop.
travelo.clj
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
| (ns logic.notmembero | |
| (:refer-clojure :exclude [reify == inc]) | |
| (:use [clojure.core.logic minikanren prelude disequality])) | |
| (defne not-membero [x l] | |
| ([_ []]) | |
| ([_ [?y . ?r]] | |
| (!= x ?y) | |
| (not-membero x ?r))) | |
| (defne reverseo [lst acum res] | |
| ([[] _ acum]) | |
| ([[?x . ?y] ?z _] | |
| (exist [w] | |
| (conso ?x ?z w) | |
| (reverseo ?y w res)))) | |
| (defrel edge start end) | |
| (fact edge 1,2) | |
| (fact edge 1,4) | |
| (fact edge 1,3) | |
| (fact edge 2,3) | |
| (fact edge 2,5) | |
| (fact edge 3,4) | |
| (fact edge 3,5) | |
| (fact edge 4,5) | |
| (defn connectedo [start end] | |
| (conde | |
| ((edge start end)) | |
| ((edge end start)))) | |
| (defne travelo [a b visited path] | |
| ([?a ?b _ [b . visited]] (connectedo ?a ?b)) | |
| ([?a ?b ?v ?p] | |
| (exist [c vis] | |
| (connectedo ?a c) | |
| (!= ?b c) | |
| (not-membero c ?v) | |
| (conso c ?v vis) ; no pairs in body? | |
| (travelo c ?b vis ?p)))) | |
| (defn patho [start end res] | |
| (exist [q] | |
| (travelo start end [start] q) | |
| (reverseo q [] res))) | |
| (comment | |
| (run* [q] | |
| (not-membero 'd '[a b c]) | |
| (== q 'd)) | |
| (run* [q] | |
| (reverseo [1 2 3 4] [] q)) | |
| (run* [q] | |
| (connectedo 1 q)) | |
| (run* [q] (patho 1 5 q)) | |
| ; ((1 2 5) | |
| ; (1 3 5) | |
| ; (1 2 3 5) | |
| ; (1 4 5) | |
| ; (1 2 3 4 5) | |
| ; (1 3 4 5) | |
| ; (1 4 3 5) | |
| ; (1 3 2 5) | |
| ; (1 4 3 2 5)) | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment