Timo Mihaljov wrote: > I'm wondering about how to change a data structure without breaking the > API used to access it. For example, let's assume that I have a library > for dealing with records of people and I'm storing them in structs. > > (defstruct person :name) > > The users of my library access the data stored in the records like any > other map. > > (:name some-person) > > When the library's been in use for a while, I realize that I need to > make a change to the data structure. > > (defstruct :first-name :last-name) > > The problem is that making this change would break all the clients using > the library.
After a bit of googling I found what seems to be the perfect solution: http://kotka.de/projects/clojure/lazy-map.html (defn new-person [first-name last-name] (lazy-struct-map person :first-name first-name :last-name last-name :name (str first-name " " last-name))) This is great news! It means I can develop in Clojure like I did in Python: start out with direct member access and transparently introduce accessors when needed. Yay! :) Now I only wish that de.kotka.lazymap would become a part of Clojure core. -- Timo --~--~---------~--~----~------------~-------~--~----~ 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 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 -~----------~----~----~----~------~----~------~--~---