Excellent; this is perfect. I wonder why I didn't find it when I
searched the docs...thanks a lot, though.

On Oct 25, 3:16 pm, Phil Hagelberg <p...@hagelb.org> wrote:
> samppi <rbysam...@gmail.com> writes:
> > with-meta's behavior is annoying for me. I often have something like
> > this:
>
> >   (defn a [blah] (with-meta blah {:type ::incredible}))
> >   (defn b [foo] (with-meta (a foo) {::b 2}))
>
> > I'd like ^(b []) to be {:type ::incredible, ::b 2}. But with-meta
> > overwrites the metadata from a completely. Is there a standard
> > function in core or contrib that does:
> >   (defn add-meta [obj obj-meta]
> >     (with-meta obj (into (meta obj) obj-meta)))
>
> I think what you want is vary-meta:
>
> user> (doc vary-meta)
> -------------------------
> clojure.core/vary-meta
> ([obj f & args])
>   Returns an object of the same type and value as obj, with
>   (apply f (meta obj) args) as its metadata.
>
> > (defn a [blah] (with-meta blah {:type ::incredible}))
> > (defn b [foo] (vary-meta (a foo) assoc ::b 2))
> > ^(b []) ;; => {:user/b 2, :type :user/incredible}
>
> -Phil
--~--~---------~--~----~------------~-------~--~----~
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