I remember not really understanding the way defn hung metadata off of its
functions. In 1.2, it returned different responses on successive calls to
defn. for example:
user> (clojure-version)
"1.2.1"
user> (defn my-func "a docstring!" [x] x)
#'user/my-func
user> (meta #'my-func) ;; var first
{:ns #<Namespace user>, :name my-func, :file "NO_SOURCE_FILE", :line 1,
:arglists ([x]), :doc "a docstring!"}
user> (meta my-func) ;; function value, before re-defn
{:ns #<Namespace user>, :name my-func}
user> (defn my-func "a docstring!" [x] x)
#'user/my-func
user> (meta my-func) ;; function value after defn the second time
{:ns #<Namespace user>, :name my-func, :file "NO_SOURCE_FILE", :line 1,
:arglists ([x]), :doc "a docstring!"}
1.3 is at least consistent:
user> (clojure-version)
"1.3.0"
user> (defn my-func "a docstring!" [x] x)
#'user/my-func
user> (meta #'my-func)
{:arglists ([x]), :ns #<Namespace user>, :name my-func, :doc "a docstring!",
:line 1, :file "NO_SOURCE_FILE"}
user> (meta my-func)
nil
user> (defn my-func "a docstring!" [x] x)
#'user/my-func
user> (meta my-func)
nil
On Tue, Oct 11, 2011 at 6:22 PM, Chas Emerick <[email protected]> wrote:
>
> On Oct 11, 2011, at 8:53 PM, Brian Marick wrote:
>
> >
> > On Oct 11, 2011, at 7:48 PM, Stuart Sierra wrote:
> >
> >> I suppose you could iterate over all known Vars and construct a map from
> fns to the Vars that contain them. Then, given a fn, you can look up the Var
> and get its metadata. It would break if anyone redefines or binds the Var,
> of course.
> >
> > How about putting the information back on the function? Who would be
> harmed by reverting back to old behavior?
>
> Much of the information in var metadata is just not applicable to the
> function — and, in the presence of binding and with-redefs, you want to be
> sure to keep function and var metadata distinct. IIRC, the application of
> function/var metadata changed when functions became eligible for "updating"
> via with-meta.
>
> That said, it seems like there are some bits of var metadata that should
> migrate to the underlying function. Probably worth filing a bug for it.
>
> - Chas
>
> --
> 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
>
--
Sam Ritchie, Twitter Inc
703.662.1337
@sritchie09
(Too brief? Here's why! http://emailcharter.org)
--
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