To start with, IObj and its .meta method are used with clojure.core/meta to get the metadata on an object. Since this method can be the same between refs and immutable data, they all use the same interface.
IMeta is used with withMeta and clojure.core/with-meta to return a new object with the given metadata. Notice that: (let [d {}] (identical? d (with-meta d {:some :meta})))) ; => false IReference however has alterMeta which is used with clojure.core/alter-meta, and as the name suggests it alters the metadata on the object. It's a mutation of the object. This is needed with refs since returning a new atom once you change the meta wouldn't be much help at all. So there you have it, use with-meta for immutable objects, and alter-meta for mutable objects. Timothy On Wed, Nov 1, 2017 at 7:20 PM, Didier <didi...@gmail.com> wrote: > Hey, I was surprised to find that IMeta does not work for (with-meta). > > So it seems that withMeta is added to IObj, which extends IMeta. And it > seems like alterMeta and resetMeta are added in IReference, which also > extends IMeta. > > So now if you want to support meta, you have to implement IReference, IObj > and IMeta? > > Is there a reason for this? Particularly, I find it strange I can't use > with-meta on a Var, because it only implements IReference, and not IObj. So > I can use all meta functions on Vars except for with-meta. > > Thank you. > > -- > 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. > -- “One of the main causes of the fall of the Roman Empire was that–lacking zero–they had no way to indicate successful termination of their C programs.” (Robert Firth) -- 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.