On Fri, Apr 29, 2011 at 2:06 AM, Meikel Brandmeyer <[email protected]> wrote:
> Hi,
>
> or just use the class name, which is what the stacktrace gives you anyway.
>
> user=> (class (fn [x] x))
> user$eval1$fn__2
> user=> (class (fn foo [x] x))
> user$eval5$foo__6
> user=> (defn bar [x] x)
> #'user/bar
> user=> (class bar)
> user$bar
> user=> (defn frob [f] (prn (class f)))
> #'user/frob
> user=> (frob (fn [x] x))
> user$eval13$fn__14
> nil
> user=> (frob (fn foo [x] x))
> user$eval17$foo__18
> nil
> user=> (frob bar)
> user$bar
> nil
Yeah, that works if you have the object in hand and it's not wrapped
or anything. Of course it has the same problem: which component are
you interested in? I guess in this case you might strip everything
before the last $, and anything starting with __ at the end, to get a
more meaningful name, though you'll sometimes get "fn" that way.
It would definitely be nice if (fn foo [...] ...) put :name foo in the
object's metadata. You could make your own version of fn that did
this, e.g.
(ns foo
(refer-clojure :exclude (fn)))
(defmacro fn [& args]
(let [x (first args)]
(if-not (symbol? x)
`(clojure.core/fn ~@args)
`(with-meta (clojure.core/fn ~@args) {:name '~x}))))
but this wouldn't magically attach name metadata to fns generated elsewhere.
--
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