When dealing with metadata, it's important to understand the difference
between these two expressions:
^{:foo :bar} baz
(with-meta baz {:foo :bar})
The first expression attaches metadata to the 'baz' symbol at compile time.
The second expression attaches metadata to the data held in 'baz' at
runtime.
The ^ syntax is essentially used for passing information to the Clojure
compiler, and to macros. It's not runtime information.
- James
On 5 May 2015 at 19:31, Andrey Antukh <[email protected]> wrote:
> Hi!
>
> I have some trouble with clojure metadata / reader and I do not know if
> I'm doing something wrong.
>
> I have this code:
>
> (defn some-func [])
>
> (def func ^:abc some-func)
>
> (assert (= (meta func) {:abc true}))
>
> (def data [[:bar (with-meta some-func {:abc true})]
> [:baz ^:abc some-func]])
>
> (assert (= (meta (get-in data [0 1])) {:abc true}))
> (assert (= (meta (get-in data [1 1])) {:abc true}))
>
> It fails in the first assert and in the last (if I comment the first one
> obviously). I do not understand why that form of metadata does not works
> as I expect (http://clojure.org/metadata)
>
> Thank you very much.
>
> Regards.
> Andrey
>
> --
> Andrey Antukh - Андрей Антух - <[email protected]> / <
> [email protected]>
> http://www.niwi.be <http://www.niwi.be/page/about/>
> https://github.com/niwibe
>
> --
> 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.