Bug report: function metadata is broken

3 views
Skip to first unread message

Mike Mazur

unread,
Jul 13, 2010, 5:52:07 AM7/13/10
to clo...@googlegroups.com
Hi,

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

This is from the latest source:

$ git remote -v
origin http://github.com/clojure/clojure.git (fetch)
origin http://github.com/clojure/clojure.git (push)
$ git rev-parse HEAD
d184ed95817c5ddfd5874ea75e83e0df7e753c24

It appears I can't create new tickets on assembla[2], so I'm posting
to the mailing list instead.

Thanks!
Mike


[1] http://clojure-log.n01se.net/#04:25
[2] http://www.assembla.com/spaces/clojure/tickets

Meikel Brandmeyer

unread,
Jul 13, 2010, 6:03:27 AM7/13/10
to Clojure
Hi,

On Jul 13, 11:52 am, Mike Mazur <mma...@gmail.com> 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

afranke

unread,
Aug 25, 2010, 6:19:42 AM8/25/10
to Clojure
On 13 Jul., 12:03, Meikel Brandmeyer <m...@kotka.de> wrote:

> I'm not sure, though, why the metadata gets moved to the function on
> redefinition.

Does anyone know why this is so?

> (defn foo [x] x)
> (defn foo [x y] (+ x y))
> (:arglists (meta (var foo))) ==> ([x y])
> (:arglists (meta foo)) ==> ([x])

Thanks,
Andreas
Reply all
Reply to author
Forward
0 new messages