Problem seeing fn metadata unless I eval or load a file

8 views
Skip to first unread message

Jim Menard

unread,
May 27, 2010, 9:28:16 AM5/27/10
to clo...@googlegroups.com
I've given some functions metadata that I want to use elsewhere. My
problem is, I don't see the metadata I've added if I use or require
the namespace; I need to explicitly load the file (or eval the
function definitions manually in slime/swank) to see the metatada.
Here's some simple code that shows my problem. What am I doing wrong,
or not understanding about metadata?

;;; ================ src/ctest/funcs.clj ================
(ns ctest.funcs)

(defn
#^{:wadl {:url "/f1" :method "GET" :doc "The f1 function."}}
f1 [] 42)

(defn
#^{:wadl {:url "/f2" :method "GET" :doc "The f2 function."}}
f2 [] "eleventy-seven")

;;; ================ src/ctest/core.clj ================
(ns ctest.core
(:use ctest.funcs))

(def wadl-meta (list (meta ctest.funcs/f1) (meta ctest.funcs/f2)))

;;; ================ in the repl (output wrapped) ================
user=> (use 'ctest.core)
nil
user=> ; I expect wadl-meta to contain the metadata added in funcs.clj
user=> ; but it does not. (Note; output is wrapped for this email)
user=> ctest.core/wadl-meta
({:ns #<Namespace ctest.funcs>, :name f1}
{:ns #<Namespace ctest.funcs>, :name f2})
user=> ; The problem isn't with the definition of wadl-meta.
user=> (meta ctest.funcs/f1)
{:ns #<Namespace ctest.funcs>, :name f1}
user=> ; Now I load the file directly (or eval the defn in Emacs)
user=> (load-file "src/ctest/funcs.clj")
#'ctest.funcs/f2
user=> ; Look! I can see the metadata I defined now. WHY??????
user=> (meta ctest.funcs/f1)
{:ns #<Namespace ctest.funcs>, :name f1, :file "ctest/funcs.clj",
:line 3, :arglists ([]),
:wadl {:url "/f1", :method "GET", :doc "The f1 function."}}

Jim
--
Jim Menard, http://www.io.com/~jimm/

Christophe Grand

unread,
May 27, 2010, 9:59:52 AM5/27/10
to clo...@googlegroups.com
Hi,

On Thu, May 27, 2010 at 3:28 PM, Jim Menard <jim.m...@gmail.com> wrote:
I've given some functions metadata that I want to use elsewhere. My
problem is, I don't see the metadata I've added if I use or require
the namespace; I need to explicitly load the file (or eval the
function definitions manually in slime/swank) to see the metatada.
Here's some simple code that shows my problem. What am I doing wrong,
or not understanding about metadata?

;;; ================ src/ctest/funcs.clj ================
(ns ctest.funcs)

(defn
 #^{:wadl {:url "/f1" :method "GET" :doc "The f1 function."}}
 f1 [] 42)

(defn
 #^{:wadl {:url "/f2" :method "GET" :doc "The f2 function."}}
 f2 [] "eleventy-seven")

;;; ================ src/ctest/core.clj ================
(ns ctest.core
 (:use ctest.funcs))

(def wadl-meta (list (meta ctest.funcs/f1) (meta ctest.funcs/f2)))

There is indeed a bug in how defn copy metadata from the var to the fn:
user=> (defn foo {:bar :baz} [] 42)
#'user/foo
user=> (meta #'foo)
{:ns #<Namespace user>, :name foo, :file "NO_SOURCE_PATH", :line 221, :arglists ([]), :bar :baz}
user=> (meta foo)
{:ns #<Namespace user>, :name foo}
user=> (defn foo {:lucy :ethel} [] 43)
#'user/foo
user=> (meta #'foo)
{:ns #<Namespace user>, :name foo, :file "NO_SOURCE_PATH", :line 224, :arglists ([]), :lucy :ethel}
user=> (meta foo)
{:ns #<Namespace user>, :name foo, :file "NO_SOURCE_PATH", :line 221, :arglists ([]), :bar :baz}

There you see that the fn got the previous metadata and not the current. I'm going to open a ticket.

Christophe

Jim Menard

unread,
May 27, 2010, 10:52:27 AM5/27/10
to clo...@googlegroups.com
Christophe,

Thank you for your research and for opening the ticket.

Jim

> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@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+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

Christophe Grand

unread,
May 28, 2010, 3:56:59 AM5/28/10
to clo...@googlegroups.com
Actually it's a duplicate of ticket #270 http://www.assembla.com/spaces/clojure/tickets/270
Brussels, 23-25/6 http://conj-labs.eu/
Professional: http://cgrand.net/ (fr)
On Clojure: http://clj-me.cgrand.net/ (en)
Reply all
Reply to author
Forward
0 new messages