我正在尝试制作core.reducers
库的头部或尾部,并且遇到以下代码行r/map
:
(defmacro ^:private defcurried
"Builds another arity of the fn that returns a fn awaiting the last
param"
[name doc meta args & body]
(do-curried name doc meta args body))
(defn- do-rfn [f1 k fkv]
`(fn
([] (~f1))
~(clojure.walk/postwalk
#(if (sequential? %)
((if (vector? %) vec identity)
(core/remove #{k} %))
%)
fkv)
~fkv))
(defmacro ^:private rfn
"Builds 3-arity reducing fn given names of wrapped fn and key, and k/v impl."
[[f1 k] fkv]
(do-rfn f1 k fkv))
(defcurried map
"Applies f to every value in the reduction of coll. Foldable."
{:added "1.5"}
[f coll]
(folder coll
(fn [f1]
(rfn [f1 k]
;; the following is k/v implementation but
([ret k v] ;; why a `vector` is placed in the beginning of a list???
(f1 ret (f k v)))))))
在defcurried map
实施中,这rfn
对我来说看起来很奇怪和不寻常,因为我不明白为什么[ret k v]
放在列表的开头。谁能解释一下?