minor refactoring of macros

This commit is contained in:
Nathan Marz 2016-08-10 15:45:13 -04:00
parent e08f12d944
commit 87137c633d

View file

@ -9,13 +9,13 @@
(defn ^:no-doc gensyms [amt] (defn ^:no-doc gensyms [amt]
(vec (repeatedly amt gensym))) (vec (repeatedly amt gensym)))
(defn ^:no-doc determine-params-impls [[name1 & impl1] [name2 & impl2]] (defn ^:no-doc determine-params-impls [impls]
(if-not (= #{name1 name2} #{'select* 'transform*}) (let [grouped (->> impls (map (fn [[n & body]] [n body])) (into {}))]
(i/throw-illegal "defnav must implement select* and transform*, instead got " (if-not (= #{'select* 'transform*} (-> grouped keys set))
name1 " and " name2)) (i/throw-illegal "defnav must implement select* and transform*, instead got "
(if (= name1 'select*) (keys grouped)))
[impl1 impl2] grouped
[impl2 impl1])) ))
(defmacro richnav (defmacro richnav
"Defines a navigator with full access to collected vals, the parameters array, "Defines a navigator with full access to collected vals, the parameters array,
@ -24,8 +24,9 @@
`next-fn` will automatically skip ahead in params array by `num-params`, so the `next-fn` will automatically skip ahead in params array by `num-params`, so the
index passed to it is ignored. index passed to it is ignored.
This is the lowest level way of making navigators." This is the lowest level way of making navigators."
[num-params impl1 impl2] [num-params & impls]
(let [[[s-params & s-body] [t-params & t-body]] (determine-params-impls impl1 impl2) (let [{[s-params & s-body] 'select*
[t-params & t-body] 'transform*} (determine-params-impls impls)
s-next-fn-sym (last s-params) s-next-fn-sym (last s-params)
s-pidx-sym (nth s-params 2) s-pidx-sym (nth s-params 2)
t-next-fn-sym (last t-params) t-next-fn-sym (last t-params)
@ -63,9 +64,9 @@
))) )))
(defmacro ^:no-doc rich-nav-with-bindings [num-params-code bindings & impls] (defmacro ^:no-doc rich-nav-with-bindings [num-params-code bindings & impls]
(let [[[[_ s-structure-sym s-next-fn-sym] & s-body] (let [{[[_ s-structure-sym s-next-fn-sym] & s-body] 'select*
[[_ t-structure-sym t-next-fn-sym] & t-body]] [[_ t-structure-sym t-next-fn-sym] & t-body] 'transform*}
(apply determine-params-impls impls) (determine-params-impls impls)
params-sym (gensym "params") params-sym (gensym "params")
params-idx-sym (gensym "params-idx") params-idx-sym (gensym "params-idx")
] ]