I use a default reader to do something like what you're asking for in my 'tagged' library. You could hack a similar default reader that restricted itself just to your favorite namespaces. That way you don't have to explicitly track all your defrecord classes.
https://github.com/miner/tagged On Fri, Dec 6, 2013 at 2:10 AM, Michael Daines <defndai...@gmail.com> wrote: > I'm trying to come up with a function that will take a namespace > containing Record definitions and convert it into a :readers map for EDN > parsing. Right now, I'm just doing it manually, but as the number of > records grows, this feels sillier and sillier. I haven't found anything in > the core libraries yet that would seem to help me here. The only "ns-" > function that gets me some of what I need is (ns-publics), which I could > use to parse out the map functions. > > To be more clear, I have a namespace in the project like this: > > (ns proj.core.records) > > (defrecord NodeAddress [node address]) > (defrecord NodeComplete [node completed status) > ... etc. > > > Then at the end of the file, I'm manually creating a map for use with EDN: > > (def reader-map > {'proj.core.records.NodeAddress map->NodeAddress > ... etc. }) > > > I feel like there should be an elegant way to do this, but I haven't seen > anything like what I have in mind. I'd love to put together a general > purpose function I could use like this: > > (edn/read-string {:readers (reader-map 'proj.core.records)} data) > > > Does anyone have some insights, or suggestions, or maybe something out > there already (this seems to me like an obvious thing to do)? > > Thanks > > -- > -- > 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. > -- -- 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.