On Jul 28, 2011, at 8:19 PM, Alex Osborne wrote: > The main use cases for the old structs feature on the other hand are > completely replaced by records and it is recommended that new code use > defrecord instead of defstruct.
I had some code using structs and, following advice like this, replaced it with code using records. The result was more complicated, uglier and not noticeably faster. I reverted to the struct version. I like structs, and I hope they are retained! -Lee PS for anyone who is curious the struct version of the code in question is as follows (with push-types having a value like '(:exec :integer :float :code :boolean :auxiliary :tag :zip)): (defmacro define-push-state-structure [] `(defstruct push-state ~@push-types)) (define-push-state-structure) (defn make-push-state "Returns an empty push state." [] (struct-map push-state)) The record version that I came up with is: (defn keyword->symbol [kwd] "Returns the symbol obtained by removing the : from a keyword." (read-string (name kwd))) (defmacro define-push-state-record-type [] "Defines the pushstate record type. The odd trick with read-string was a hack to avoid namespace qualification on the pushstate symbol." `(defrecord ~(read-string "pushstate") [~@(map keyword->symbol push-types)])) (define-push-state-record-type) (defmacro make-push-state "Returns an empty push state." [] `(pushstate. ~@(map (fn [_] nil) push-types))) Maybe there's a better way -- I wouldn't doubt it -- but the struct version was simple and worked exactly like I wanted it to, so I decided to stop tinkering. -- 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