On 12 June 2010 04:51, Eugen Dück <eu...@dueck.org> wrote: > I put the first part of my implementation online: > http://read-eval-puke.blogspot.com/2010/06/icfp-2009-orbit-binary-file-reader.html > so anyone who's interested do have a look.
Interesting, thanks! > There's one question that came up when I implemented this. Is there a > way to get the name of a clojure function, when all I have is the > function object? Is it stored alongside the function? I didn't see any > metadata or anything. Would I really have to reverse lookup the name > in some namespace maps? In 1.2, defn-created functions have :name metadata. I mean the fns themselves, not only the Vars. In 1.1, functions can't have metadata attached to them, so if you're planning to use that, this won't help. At any rate, for whichever reason, fn-created functions currently have no :name metadata even if explicitly given a name, e.g. (meta (fn foo [] :foo)) => nil. Still, one can interrogate a function to find out its name in the following super-clumsy way (not to say there isn't a better way -- just my first shot): (defn fn-name [the-fn] (->> (.toString the-fn) (.split #"\$") next second (.split #"_") first)) (fn-name (fn foo [] :foo)) ; => "foo" (fn-name (fn [] :foo)) ; => "fn" ; generic response for anonymous fns I wonder if perhaps the reflection api might provide a cleaner way to get at this information... Sincerely, Michał -- 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