この関数は機能しますが、私は 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)))