Skip to content
Browse files

remove excess gensyms

Thanks to tip from amalloy
  • Loading branch information...
1 parent a514300 commit 1cc8e0fb35333673c7e7a32fb0b79e57198767f8 @duck1123 committed Oct 24, 2012
Showing with 37 additions and 37 deletions.
  1. +37 −37 src/ciste/sections.clj
View
74 src/ciste/sections.clj
@@ -62,67 +62,67 @@ Example:
(defmacro declare-section
"Setup a section with the given name"
[name & opts]
- (let [name# name
- dispatch-name# (if (= (first opts) :seq)
+ (let [dispatch-name (if (= (first opts) :seq)
"record-class-seq" "record-class" )
;; Find a way to make this automatic
;; One option would be to capture the ns outside the defmacro,
;; creating a closure. I'm not sure if that's bad practice, however.
- dispatch-ns# (the-ns 'ciste.sections)
+ dispatch-ns (the-ns 'ciste.sections)
- dispatch-fn# (ns-resolve dispatch-ns# (symbol dispatch-name#))
- serialization-dispatch# (ns-resolve dispatch-ns# (symbol (str dispatch-name# "-serialization")))
- format-dispatch# (ns-resolve dispatch-ns# (symbol (str dispatch-name# "-format")))
-
- serialization-name# (symbol (str name# "-serialization"))
- format-name# (symbol (str name# "-format"))
- type-name# (symbol (str name# "-type"))]
+ dispatch-fn (ns-resolve dispatch-ns
+ (symbol dispatch-name))
+ serialization-dispatch (ns-resolve dispatch-ns
+ (symbol (str dispatch-name "-serialization")))
+ format-dispatch (ns-resolve dispatch-ns
+ (symbol (str dispatch-name "-format")))
+
+ serialization-name (symbol (str name "-serialization"))
+ format-name (symbol (str name "-format"))
+ type-name (symbol (str name "-type"))]
`(do
- (defmulti ~serialization-name# ~serialization-dispatch#)
- (defmulti ~format-name# ~format-dispatch#)
- (defmulti ~type-name# ~dispatch-fn#)
+ (defmulti ~serialization-name ~serialization-dispatch)
+ (defmulti ~format-name ~format-dispatch)
+ (defmulti ~type-name ~dispatch-fn)
- (defn ~name#
+ (defn ~name
[record# & options#]
(if *format*
(if *serialization*
- (apply ~serialization-name# record# options#)
+ (apply ~serialization-name record# options#)
(throw (IllegalArgumentException.
"serialization not provided and *serialization* not set")))
(throw (IllegalArgumentException.
"format not provided and *format* not set"))))
- (defmethod ~serialization-name# :default
+ (defmethod ~serialization-name :default
[record# & others#]
- (apply ~format-name# record# others#))
+ (apply ~format-name record# others#))
- (defmethod ~format-name# :default
+ (defmethod ~format-name :default
[record# & others#]
- (apply ~type-name# record# others#)))))
+ (apply ~type-name record# others#)))))
(defn log-section
[sym dispatch-val]
(log/debugf "%s - %s" dispatch-val sym))
(defmacro defsection
[name dispatch-val binding-form & body]
- (let [name# name]
- (if-let [declared-ns# (-> name resolve meta :ns)]
- (let [dispatch-val# dispatch-val
- type-name# (symbol (str name# "-type"))
- format-name# (symbol (str name# "-format"))
- serialization-name# (symbol (str name# "-serialization"))
- method-name# (if (= dispatch-val# :default)
- type-name#
- (condp = (count dispatch-val#)
- 3 serialization-name#
- 2 format-name#
- type-name#))
- full-symbol# (symbol (str declared-ns# "/" method-name#))]
- `(defmethod ~full-symbol# ~dispatch-val#
- ~binding-form
- (log-section '~name# '~dispatch-val#)
- ~@body))
- (throw (IllegalArgumentException. (str "Can not resolve section: " name))))))
+ (if-let [declared-ns# (-> name resolve meta :ns)]
+ (let [type-name (symbol (str name "-type"))
+ format-name (symbol (str name "-format"))
+ serialization-name (symbol (str name "-serialization"))
+ method-name (if (= dispatch-val :default)
+ type-name
+ (condp = (count dispatch-val)
+ 3 serialization-name
+ 2 format-name
+ type-name))
+ full-symbol (symbol (str declared-ns# "/" method-name))]
+ `(defmethod ~full-symbol ~dispatch-val
+ ~binding-form
+ (log-section '~name '~dispatch-val)
+ ~@body))
+ (throw (IllegalArgumentException. (str "Can not resolve section: " name)))))

0 comments on commit 1cc8e0f

Please sign in to comment.
Something went wrong with that request. Please try again.