Can I make clojure macro that will allow me to get a list of all functions created by the macro?
Posted
by Rob Lachlan
on Stack Overflow
See other posts from Stack Overflow
or by Rob Lachlan
Published on 2010-06-01T21:11:06Z
Indexed on
2010/06/01
21:13 UTC
Read the original article
Hit count: 415
I would like to have a macro which I'll call def-foo. Def-foo will create a function, and then will add this function to a set.
So I could call
(def-foo bar ...)
(def-foo baz ...)
And then there would be some set, e.g. all-foos, which I could call:
all-foos
=> #{bar, baz}
Essentially, I'm just trying to avoid repeating myself. I could of course define the functions in the normal way, (defn bar ...) and then write the set manually.
A better alternative, and simpler than the macro idea, would be to do:
(def foos #{(defn bar ...) (defn baz ...)} )
But I'm still curious as to whether there is a good way for the macro idea to work.
© Stack Overflow or respective owner