For one, the type of a record is not as malleable as the other attributes of the record. It's less dynamic.
2011/2/18 Base <basselh...@gmail.com> > Thank you Stuart! This makes perfect sense and is quite elegant. > > So is performance the only compelling reason to do this? I am assuming > there are times that maps are 'good enough', but would you say that if > you ever have a defined data structure you would advise to use > defrecord to gain this increase in speed? Are there some things that > you can do with maps that you cannot do with defrecord? > > On Feb 18, 3:05 pm, Stuart Sierra <the.stuart.sie...@gmail.com> wrote: > > Hi Base, > > > > It's easy, because instances of defrecord behave identically to maps. > Say > > you have a lot of "person" records that look like this: > > > > {:first-name "Stuart", :last-name "Sierra", :location "NYC"} > > > > You might write a constructor function to create these maps: > > > > (defn person [& options] > > (apply hash-map options)) > > > > You use the `person` function to create "person" maps, and you manipulate > > them using Clojure's map functions (assoc, dissoc, get, etc.). You can > > easily add or remove keys in the map as you develop your application. > > > > Then you want "person" records to be smaller and faster. So you write: > > > > (defrecord Person [first-name last-name location]) > > > > (defn person [& options] > > (let [{:keys [first-name last-name location]} options] > > (Person. first-name last-name location))) > > > > Poof! None of your existing code has to change how it creates and > > manipulates "person"s, but all your maps are now records. > > > > -Stuart Sierra > > clojure.com > > -- > 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