^x attaches the metadata to a form *before* it is evaluated. The with-meta
function attaches the metadata to a form *after* it's been evaluated.

Generally speaking, the ^x form is used for attaching metadata used by
macros and the Clojure compiler, whereas with-meta is used to attach
run-time metadata to Clojure data structures.

- James


On 8 May 2014 13:34, Pascal Germroth <funkyco...@gmail.com> wrote:

> Hi,
>
> I'm trying to attach metadata to some values (not the vars holding them).
> I thought ^{x} y was the same as (with-meta y {x}), but while it works for
> f2/f4, f1's metadata is nowhere to be found, while f3 works as expected:
>
> (def f1 "doc" ^{:x 1} (partial inc))
> (meta f1) ; nil, unexpected
> (meta #'f1) ; contains :doc, but not :x, as expected
>
> (def f2 "doc" ^{:x 2} #(inc %))
> (meta f2) ; {:x 2}, as expected
> (meta #'f2) ; contains :doc, but not :x, as expected
>
> (def f3 "doc" (with-meta (partial inc) {:x 3}))
> (meta f3) ; {:x 3}
>
> (def f4 "doc" (with-meta #(inc %) {:x 4}))
> (meta f4) ; {:x 4}
>
> Cheers,
>
> --
> pascal
>
> --
> 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.
>

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