Did you just need the name of the function? something like this?
---------------->8----8<----------------
(def ^{:dynamic true} *myself* nil)
(defmacro defn* [name args & body]
`(defn ~name ~args
(binding [*myself* '~name]
~@body)))
(defn* foo [a b] [*myself* (+ a b)])
---------------->8----8<----------------
This is, of course, quite ugly and grossly oversimplified, but would work for a
limited use case.
Cheers,
-ram
On Wednesday, March 28, 2012 at 8:02 AM, Shantanu Kumar wrote:
> Hi,
>
> Is it possible to write a macro that when used in a top-level function
> (created using defn) can find out the name of the immediate top-level
> function? I know *ns* returns the namespace and it's possible to walk
> the current thread's stack trace to find out the function name, but I
> am looking for a computationally cheap way to do it.
>
> Thanks,
> Shantanu
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to [email protected]
> (mailto:[email protected])
> Note that posts from new members are moderated - please be patient with your
> first post.
> To unsubscribe from this group, send email to
> [email protected]
> (mailto:[email protected])
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>
>
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en