On Wednesday, March 28, 2012 at 9:15 AM, Shantanu Kumar wrote: > > > On Mar 28, 8:57 pm, Ram Krishnan <kriyat...@gmail.com (http://gmail.com)> > wrote: > > Did you just need the name of the function? something like this? > > > Sorry, I should explained using code what I am looking for: > > (defmacro find-name [] > ;; some magic here > ..) > > (defn foo [] > .. > (println (find-name)) ; should print "foo" > ..) > > I am looking for a way to write the `find-name` macro. So, you can see > I want to use it with regular functions defined using `defn`. > >
If you can't use a specialized `defn` you could try something like the following, assuming that you need this for just a temporary while (say during development): ---------------->8----8<---------------- (def ^{:dynamic true} *myself* nil) (defn find-name [] *myself*) (defmacro trace [sym] `(let [old# ~sym] (def ~sym (fn [& args#] (binding [*myself* '~sym] (apply old# args#)))))) (defn foo [a b] [(find-name) (+ a b)]) (foo 1 2) => [nil 3] (trace foo) (foo 1 2) => [foo 3] ---------------->8----8<---------------- It requires you explicitly `trace` the functions within which you want to call `find-name`, otherwise the name will just be `nil`. > > Shantanu > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > (mailto:clojure@googlegroups.com) > Note that posts from new members are moderated - please be patient with your > first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > (mailto:clojure+unsubscr...@googlegroups.com) > 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 clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en