Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
assoco.clj
(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
You can’t perform that action at this time.