Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
deterministic gentemp
(def ^:dynamic *gentemp-counters*)
(defn new-gentemp-counters [] {})
(defn next-name [name]
(let [c (get *gentemp-counters* name 0)]
(set! *gentemp-counters* (assoc *gentemp-counters* name (inc c)))
(str name "-" c)))
(defmacro with-reset-ids [& body]
`(binding [*gentemp-counters* (new-gentemp-counters)]
~@body)
@drlivingston

This comment has been minimized.

Copy link
Owner Author

commented Apr 17, 2012

e.g.

> (with-reset-ids (next-name "foo")
                        (next-name "foo"))
"foo-1"
> (with-reset-ids (next-name "foo")
                        (next-name "foo")
                        (next-name "foo"))
"foo-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.