I was actually thinking of the case where the metadata was computed in some way from the Java object (i.e. when it is more like read-only property). In most of the cases where I have wanted metadata on arbitrary Java objects, this would have been sufficient.
You probably want to go the wrapper route if you want first-class metadata behaviour (with-meta et al.) - in effect you would be creating a new kind of object with a new kind of "state" so it's better to wrap (and maybe simultaneously add a nice wrapper API with idiomatic Clojure style) than to try and pretend that the Java Object is something that it isn't. The alternatives of a global metadata map or some kind of memoization look really messy to implement - they wouldn't play nicely with the varying immutable vs. mutable update semantics that you might see on arbitrary Java objects, they often cause subtle concurrency issues and global state is usually a bad idea anyway. It might just work if you limit yourself to one-off assignment of metadata to object instances, but even that is problematic (cloning the Java object wouldn't preserve metadata, for example) On Sunday, 1 September 2013 21:58:25 UTC+8, Colin Jones wrote: > > I thought of protocols initially here too, but protocols just define > functions, so where would the data live that you want as metadata? > > A closure over the data? This implies extending the protocol on a > per-instance basis, which afaik doesn't exist (cljs design work aside > http://dev.clojure.org/display/design/specify+i.e.+reify+for+instances). > > Some global map? We can't key on arbitrary java objects since the hashcode > can change. Is there a key that will work? > > A var? We can already do that. > > Maybe there's someplace I'm missing where you could store this data and > look it up later via a protocol implementation? > > -- -- 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/groups/opt_out.