Re: defstruct defrecord metadata
Is this thread related to http://dev.clojure.org/jira/browse/CLJ-304 ? Would be nice to address that issue. -FrankS. On May 16, 2012, at 6:54 AM, Tim Visher wrote: On Tue, May 15, 2012 at 12:11 PM, JDuPreez jacques...@gmail.com wrote: Maybe I should post my solution to this problem here? Sounds like a plan. :) -- 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 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
Re: defstruct defrecord metadata
On Tue, May 15, 2012 at 12:11 PM, JDuPreez jacques...@gmail.com wrote: Maybe I should post my solution to this problem here? Sounds like a plan. :) -- 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
Re: defstruct defrecord metadata
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
Re: defstruct defrecord metadata
Hi, I am not sure whether I fully understand your question. However, when you create a record, a second constructor will be created for you which also expects a meta-data map: user= (defrecord Foo (bar baz)) user= (meta (Foo. 2 3 {:foo meta} nil)) {:foo meta} Hope that helps. Stefan -- 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
Re: defstruct defrecord metadata
Stefan, Thank you for your reply. You are referring to applying an annotation to an instance/object. If we could imagine it existed for the moment, this is what I'd be looking for: (meta {:foo meta} (defrecord Foo (bar baz))) I should then somehow be able to retrieve the metadata of the type definition, given an instance of it. In other words, given an instance of record Foo, I should be able to get to the metadata of its defrecord definition. Maybe I should post my solution to this problem here? Thanks! Jacques On Tuesday, May 15, 2012 4:51:15 PM UTC+2, Stefan Kamphausen wrote: Hi, I am not sure whether I fully understand your question. However, when you create a record, a second constructor will be created for you which also expects a meta-data map: user= (defrecord Foo (bar baz)) user= (meta (Foo. 2 3 {:foo meta} nil)) {:foo meta} Hope that helps. Stefan -- 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
defstruct defrecord metadata
Hi, 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! Jacques -- 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