此功能有效,但我正在学习 Clojure 并想知道是否有更好/更清洁的方法来编写:
;; loop over methods, update the scripts map, and return scripts
(defn update-scripts
[filename]
(loop [scripts {}
methods (get-methods filename)]
(if (seq methods)
(let [method (first methods)
sig (get-method-signature method)
name (get-method-name sig)]
(recur (assoc scripts name {:sig sig, :method method})
(rest methods)))
scripts)))
(update-scripts "gremlin.groovy")
更新:这是我最终使用的:
(defn- update-scripts
[scripts method]
(let [sig (get-method-signature method)
name (get-method-name sig)]
(assoc scripts name {:sig sig :method method})))
(defn get-scripts
[filename]
(reduce update-scripts {} (get-methods filename)))