On Fri, Sep 4, 2015 at 11:30 AM, Gregg Reynolds <d...@mobileink.com> wrote:

> I have a deftype that supports with-meta, but I can't figure out how to
> support caret reader syntax.
>
> To support with-meta, I include a "meta" field and implement IObj methods
> "meta" and "withMeta".  Seems to work just fine:
>
>     (with-meta (entity-map [:A/B] {:a 1})  {:foo "metadata here"})
>
> But this doesn't work:  ^{:foo "metadata there"}(entity-map [:A/B] {:a 1})
>

Ok, so (entity-map...) is passed to the MetaReader as a PersistentList.  Of
course.  And if I say (def em (entity-map [:A/B] {:a 2})) and then say (def
em2 ^{:foo "bar"} em), then em gets passed as a symbol so the metadata does
not stick.

So it looks like you can only use caret metadata syntax with forms, rather
than types/values.  If I wanted my deftype to support caret metadata,  I
would have to defined a custom reader syntax for it, which as I understand
is not currently possible.  Does that sound accurate?

Then again, the doc says

*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."

So let's try a Symbol:
  (symbol? 'a) is true,
 (instance? clojure.lang.IMeta 'a) is true, but
 (meta ^{:foo 3} 'a)  is nil, while
 (meta ^{:foo 4} [1 2])  is {:foo 4}

So now I'm confused.  Is the documentation just out of sync or am I
misunderstanding something?

Thanks,

Gregg

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