Wednesday, 15 September 2010

clojure - Documenting functions defined using point-free style -



clojure - Documenting functions defined using point-free style -

when creating library in clojure, it's practice include docstrings , other metadata on each function, e.g.:

(defn ^boolean foo "returns whether x bar." {:added "1.5"} [x] (bar? x))

sometimes (when working higher-order functions) ends beingness easier define function using def (something-that-returns-a-fn), this:

(defn wrapper [f] "some hof, let's prints 'wharrgarbl' , returns fn." (println "wharrgarbl") f) (def foo "prints 'wharrgarbl' , returns whether x bar." (wrapper (fn [x] (bar? x))))

if i'm not mistaken, defining functions in way nullifies advantages of using defn -- namely, docstring beingness printed in nice way includes arities function supports, , ability concisely include attribute map within function definition. right, or there other concise way document functions created via hofs? this:

(defn foo "prints 'wharrgarbl' , returns whether x bar." {:added "1.5"} [x] ((wrapper (fn [y] (bar? y))) x))

but seems little redundant , unnecessarily complicated, i'm defining function of x function of y, applied x. there improve way?

you can add together whatever metadata wish def.

(def ^{:doc "does something." :added "1.5" :arglists '([x]) } foo (wrapper (fn [x] (bar? x))))

clojure metadata docstring

No comments:

Post a Comment