Hi,
On Jul 13, 11:52 am, Mike Mazur <[email protected]> wrote:
> I asked in the IRC channel about metadata on functions[1], and was
> told that it's indeed possible in 1.2. I tried this at the REPL and
> saw the following behavior (which looks like a bug):
>
> user=> (defn ^{:foo "v1.0"} mfoo "mfoo docstring" [] (println "foo v1.0"))
> #'user/mfoo
> user=> (meta mfoo)
> {:ns #<Namespace user>, :name mfoo}
> user=> (mfoo)
> foo v1.0
> nil
> user=> (defn ^{:foo "v2.0"} mfoo "mfoo docstring" [] (println "foo v2.0"))
> #'user/mfoo
> user=> (meta mfoo)
> {:ns #<Namespace user>, :name mfoo, :file "NO_SOURCE_PATH", :line
> 33, :arglists ([]), :doc "mfoo docstring", :foo "v1.0"}
> user=> (mfoo)
> foo v2.0
> nil
Metadata on functions works as expected:
user=> (meta (with-meta (fn [] :with-meta) {:foo "v1.0"}))
{:foo "v1.0"}
Hinting the argument to defn (or providing the optional meta map)
attaches the metadata to the Var:
user=> (defn ^{:mfoo "v1.0"} mfoo "mfoo docstring" {:foo "v1.0"} []
(println "foo v1.0"))
#'user/mfoo
user=> (meta #'mfoo)
{:ns #<Namespace user>, :name mfoo, :file "NO_SOURCE_PATH", :line
1, :arglists ([]), :foo "v1.0", :doc "mfoo docstring", :mfoo "v1.0"}
user=> (meta mfoo)
{:ns #<Namespace user>, :name mfoo}
I'm not sure, though, why the metadata gets moved to the function on
redefinition.
Sincerely
Meikel
--
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