Skip to content

Instantly share code, notes, and snippets.

@amalloy
Created February 22, 2011 20:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amalloy/3d5d85f19505295c9a32 to your computer and use it in GitHub Desktop.
Save amalloy/3d5d85f19505295c9a32 to your computer and use it in GitHub Desktop.
(defmacro counted-meta [& defns]
(cons 'do
(for [[i [name & body]] (map-indexed vector defns)]
`(defn ~(vary-meta name assoc :count i) ~@body))))
user> (counted-meta (f [] 10) (^{:private true} bar [x] (inc x)))
#'user/bar
user> (meta #'bar)
{:ns #<Namespace user>, :name bar, :file "NO_SOURCE_FILE", :line 1, :arglists ([x]), :count 1, :private true}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment