Like so:
java -cp clojure.jar clojure.main
Clojure 1.2.0
user=> (defn f [x] x)
#'user/f
user=> (meta f)
{:ns #<Namespace user>, :name f}
user=> (defn f [x] x)
#'user/f
user=> (meta f)
{:ns #<Namespace user>, :name f, :file "NO_SOURCE_PATH", :line 1, :arglists ([x])}
user=>
Why doesn’t the call to meta return the same value each time?
UPDATE: by playing some more I was able to get an answer to my immediate question. defn macro-expands to a form which adds (meta (var f) to f‘s metadata. And (meta (var f) includes the extra info that isn’t in (meta f) when f is defined the first time. So my question now becomes, why is defn implemented like this?
java -cp clojure.jar clojure.main
Clojure 1.2.0
user=> (defn f [x] x)
#'user/f
user=> (meta f)
{:ns #<Namespace user>, :name f}
user=> (meta (var f))
{:ns #<Namespace user>, :name f, :file "NO_SOURCE_PATH", :line 1, :arglists ([x])}
user=> (macroexpand '(defn f [x] x))
(def f (.withMeta (clojure.core/fn f ([x] x)) (.meta (var f)))) ; (.meta x) seems to be the same as (meta x)
user=>
Apparently this behaviour was more or less “accidental” in Clojure 1.2, and has been changed in 1.3:
http://groups.google.com/group/clojure/browse_thread/thread/964bba0ead8218ee/3ef0c841474c85f4?lnk=gst&q=function+meta+data#3ef0c841474c85f4
In 1.3, only the Var includes the metadata – the function itself isn’t assigned any metadata by
defn.