Hi,

On Nov 27, 10:19 am, Stefan Kamphausen <ska2...@googlemail.com> wrote:

> As far as the documentation says, Vars can't have metadata:
>
> "Symbols and collections support metadata," --http://clojure.org/metadata
>
> "Symbols, Lists, Vector, Sets and Maps can have metadata" 
> --http://clojure.org/reader
>
> I tried to understand the Java implementation underneath which seems
> to be in line with the documentation.  E.g. a symbol extends AFn,
> which extents Obj which implements IObj, which in turn extends IMeta
> which seems to be the relevant implementation of the metadata
> interface.
>
> However, there is some metadata code in Var.java which indicates that
> Vars *can* have metadata, but according to documentation they can't.

Vars are one of the four reference types implementing IReference. The
other three are Refs, Agents and Atoms. All IReference types support
metadata.

> An example also seems to indicate that Vars can have metadata:
>
> user=> (def #^{:hasmeta "yes"} my-var [1 2 3])
> #'user/my-var
> user=> (meta my-var)
> nil

meta is a normal function. That means in the above case that meta is
called in the vector.

user=> (def #^{:hasmeta "yes"} my-var (with-meta [1 2 3] {:foo :bar}))
#'user/my-var
user=> (meta my-var)
{:foo :bar}

> Really? Then why the metadata of the symbol empty?
> user=> (meta 'greet)
> nil

Because the is a different symbol which happens to have the same name.

user=> (= 'greet 'greet)
true
user=> (identical? 'greet 'greet)
false
user=> (= 'greet (with-meta 'greet {:foo :bar}))
true

> Or am I not accessing the symbol's metadata that way?

You are. But of a different symbol. ;)

> * Is the documentation wrong or my understanding of it?

Hmm.. It seems missing, but I'm sure I read somewhere about the
reference types. Maybe in one Rich's talks? Hmmm..

> * What part of the (Java)-code should I read to understand the
> implementation of metadata (if I assume that my understanding of how
> the classes extent/implement is not correct).

The chain is Var -> Aref -> AReference -> IReference -> IMeta

> The reason for asking this is, that I *really* want to understand what
> I am talking about.

That's a Good Thing. We live to much from assumptions.

Sincerely
Meikel

-- 
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

Reply via email to