Created
July 24, 2011 00:32
-
-
Save swannodette/1102041 to your computer and use it in GitHub Desktop.
assoco.clj
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
(defne assoco [m k v o] | |
([[] _ _ [[k v]]]) | |
([[[k v] . _] _ _ m]) | |
([[[k ?v] . ?r] _ _ [[k v] . ?r]] | |
(!= m o)) | |
([[[?j v]] _ _ [[?j v] [k v]]] | |
(!= ?j k)) | |
([[[?j ?u] . ?r] _ _ [[?j ?u] . ?o]] | |
(!= ?j k) | |
(!= m o) | |
(assoco ?r k v ?o))) | |
(defne containso [m k] | |
([[[k ?v] . _] _]) | |
([[[?k ?v] . ?r] _] | |
(!= ?k k) | |
(containso ?r k))) | |
(defne findo [m k o] | |
([[k ?v] _ [k ?v]]) | |
([[[?k ?v] . ?r] _ _] | |
(!= k ?k) | |
(findo ?r k o))) | |
(run* [q] | |
(assoco [] :a 1 q)) | |
; ([[:a 1]]) | |
(run* [q] | |
(assoco q :a 1 [[:a 1]])) | |
; ([] ([:a 1]) ([:a _.0])) | |
(run* [q] | |
(exist [m] | |
(assoco [] :a 1 m) | |
(assoco m :a 2 q))) | |
; ([[:a 2]]) | |
(run* [q] | |
(exist [m] | |
(assoco [] :a 1 m) | |
(assoco m :b 2 q))) | |
; (([:a 1] [:b 2])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment