The metadata is attached to the symbol, before the form is evaluated. You
can see this with a macro:
(defmacro foo [x] (meta x))
(foo ^:bar baz) ;=> {:bar true}
The with-meta function attaches metadata to the value the symbol evaluates
to.
- James
On 3 May 2014 22:10, Angel Java Lopez <[email protected]> wrote:
> I'm trying to implement in my clojure interpreter (in c#) the metadata
> reader. I read in core.clj something like
>
> (ns ^{:doc "The core Clojure language."
> :author "Rich Hickey"}
> clojure.core)
>
> I just read:
>
> http://clojure.org/reader
>
>
> - Metadata (^)
> Metadata is a map associated with some kinds of objects: Symbols,
> Lists, Vector, Sets, Maps, tagged literals returning an IMeta, and record,
> type, and constructor calls. The metadata reader macro first reads the
> metadata and attaches it to the next form read (see
> with-meta<http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/with-meta>
> to
> attach meta to an object):
> ^{:a 1 :b 2} [1 2 3] yields the vector [1 2 3] with a metadata map of
> {:a 1 :b 2}.
>
>
> Ok, but how the reader works?
>
> I tried
>
> (def one 1)
>
> ^:foo one
>
> and it works
>
> But i tried
>
> ^:foo bar
>
> and it yields an error (Unable to resolve the symbol bar...)
>
> But then
>
> (ns ^:foo bar)
>
> IT WORKS!
>
> Where the attached form to metadata is evaluated?
>
> I thought that
>
> ^:foo bar
>
> was expanded as
>
> (with-meta bar {:foo true})
>
> in the same way like
>
> 'a
>
> is expanded to
>
> (quote a)
>
> and then (with-meta bar {:foo true}) is passed to ns.
>
> I know that ns is a macro. So the attachment of the metadata is not yet
> evaluated. But when it is evaluated? Is it true that ns receives
> (with-meta bar {:foo true})? Or in which way the ^ reader works?
>
> I checked ns source
> https://github.com/clojure/clojure/blob/028af0e0b271aa558ea44780e5d951f4932c7842/src/clj/clojure/core.clj#L5304but
> apparently it is some magic detecting the metadata
>
> Any clue?
>
> Angel "Java" Lopez
> @ajlopez
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to [email protected]
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> [email protected]
> 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 [email protected].
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/d/optout.