Hi, clojure.contrib.types/deftype assumes data to tag are created fresh with no meta data. Would it be useful to have it update meta data if data are already initialized with meta data, e.g. from file or db with other meta data, but :type ::constructor are too program specific to be stored in there?
A usage like following. x is read from database. user=> (meta x) {:last-updated #<Date Sun May 24 00:42:19 EDT 2009>} user=> (deftype ::person person) #<MultiFn clojure.lang.mult...@d063fd> user=> (meta (person x)) {:type :user/person, :clojure.contrib.types/constructor user/ person, :last-updated #<Date Sun May 24 00:42:19 EDT 2009>} Here is a simple patch. It merges deftype meta into original meta data, and it overrides existing deftype meta if they already exist (this is just to keep things simple. I haven't thought it much. Just assuming user knows new type should be compatible with old type in some context). Index: src/clojure/contrib/types.clj =================================================================== --- src/clojure/contrib/types.clj (revision 840) +++ src/clojure/contrib/types.clj (working copy) @@ -80,9 +80,9 @@ ::constructor (quote ~(qualified-symbol constructor- name))}] (def ~constructor-name - (comp (fn [~'x] (with-meta ~'x meta-map#)) ~constructor)) + (comp (fn [~'x] (with-meta ~'x (merge (meta ~'x) meta- map#))) ~constructor)) (defmethod deconstruct ~type-tag [~'x] - (~deconstructor (with-meta ~'x {}))))))) + (~deconstructor (with-meta ~'x (dissoc (meta ~'x) {:type ::constructor})))))))) (defmacro deftype- "Same as deftype but the constructor is private." Regards, - Feng --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---