On Sat, May 12, 2012 at 3:48 PM, JDuPreez <jacques...@gmail.com> wrote: > I'm new to Clojure. I've been unsuccessful in finding a clear answer or > getting it to work (might just have done it incorrectly, since I'm still > learning). I understand that you can add metadata to an object, "with-meta", > and to a variable or parameter, "^{:". However, I would like to apply > metadata to defrecord and defstruct, so that the data type definitions are > associated with the metadata. This will be the same as applying an > annotation to a Java class. > > Does Clojure support something similar? If so, please provide a simple > example of how it will be applied to, and read from, a defrecord and > defstruct. If Clojure doesn't, then that's okay as well, as I've found a > relatively straight forward way to achieve the same result. I just want to > make sure I'm not missing something before going ahead using my custom > annotation mechanism. > > Really appreciate the help. Thanks!
Don't think I'll be much help but maybe I can unofficially confirm your findings. Looking through the various implementation details ([defrecord][], [emit-defrecord][], [emit-deftype*][]) I can't see any way that you can attach custom meta-data to any of the products of those constructs at the time of their construction. None of arguments are used in the metadata of the artifacts. They do associate metadata with the class produced, but I'm not sure to what degree you can affect that definition post macro-expansion. If you can affect the definition of that class post-expansion then you should be good to go. [emit-deftype*]: https://github.com/clojure/clojure/blob/master/src/clj/clojure/core_deftype.clj#L361 [emit-defrecord]: https://github.com/clojure/clojure/blob/master/src/clj/clojure/core_deftype.clj#L140 [defrecord]: https://github.com/clojure/clojure/blob/6d84867f4c892159ad48f6ef4b56f11567b2172c/src/clj/clojure/core_deftype.clj#L257 -- 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