Metadata can be attached to many kinds of objects: functions, vars, 
collections, references, etc.

Metadata added in defn is added to the global Var which is holding the 
newly created function. 

user=> (defn ^{:foo 42} my-fn [])
#'user/my-fn
user=> (:foo (meta #'my-fn)) ;; same as (:foo (meta (var my-fn)))
42
user=> (:foo (meta my-fn))
nil

If you later store that function e.g. in a map, you are storing a function, 
not var.

Your code throws because 'var' is a special form and it accepts only a 
symbol, which names a global var.

To get metadata froma function, just call

user=> (meta my-fn)
nil

By default, there is no metadata attached to the function itself. You add 
some with with-meta, if you wish.

Best,
Jozef 

On Friday, March 14, 2014 5:31:36 PM UTC+1, Adam Krieg wrote:
>
> I'm trying to get the meta data off a function that was stored in a map,
>
> (defn my-fun [x] x)
>
> (def fun-map {:function my-fun})
>
>
> (meta (var my-fun)) ; this works
> (meta (var (:function fun-map))) ; This fails with CompilerException 
> java.lang.ClassCastException: clojure.lang.PersistentList cannot be cast to 
> clojure.lang.Symbol, compiling:
>
>
> It's not clear to me what is going on here as both my-fun and (:function 
> fun-map) resolve to the same value.
>
> Is this expected behavior?
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to