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

Reply via email to