From 4a70951d22e9b521d10a88d579f131745e847e16 Mon Sep 17 00:00:00 2001 From: Leon Barrett Date: Thu, 4 Jun 2015 19:22:55 -0700 Subject: [PATCH] Suggestion for macro --- src/clj/com/rpl/specter/impl.clj | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/clj/com/rpl/specter/impl.clj b/src/clj/com/rpl/specter/impl.clj index 095cd1c..c64acb0 100644 --- a/src/clj/com/rpl/specter/impl.clj +++ b/src/clj/com/rpl/specter/impl.clj @@ -47,6 +47,16 @@ (defprotocol CoerceTransformFunctions (coerce-path [this])) +;; In addition to the warning below, maybe just add a macro that makes it easy +;; for people to define records the way you recommend? It might be easier to +;; say "use my defrecord instead" than to explain what the advantage is. +(defmacro defrecord* + [name- elts protocol & impls] + ~(do (defrecord ~name- ~elts) + (extend-protocol + ~protocol ~name- + ~@impls))) + (defn no-prot-error-str [obj] (str "Protocol implementation cannot be found for object. Extending Specter protocols should not be done inline in a deftype definition