Skip to content

Instantly share code, notes, and snippets.

@austinhaas
Created February 9, 2013 03:02
Show Gist options
  • Save austinhaas/4743651 to your computer and use it in GitHub Desktop.
Save austinhaas/4743651 to your computer and use it in GitHub Desktop.
(ns replo
(:refer-clojure :exclude [==])
(:use [clojure.core.logic]))
(defn replo
"A relation between two sequences in and out, such that out is the
same as in, except that all occurences of k have been replaced with
v."
[k v in out]
(matche [in out]
[[() ()]]
[[(k . d) (v . e)] (replo k v d e)]
[[(a . d) (b . e)]
(conda
[(replo k v a b) (replo k v d e)]
[(== a b) (replo k v d e)])]))
(run 1 [q]
(fresh [k v in out]
(== k 'p)
(== v 'q)
(== in '((p) x))
;;(== out '((q) x))
(replo k v in out)
(== q [k v in out])))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment