I tried the following code (learning about macros):
(require '[clojure.template :as temp])
(defn fna [x] (println "a" x) x)
(defn fnb [x] (println "b" x) x)
(temp/apply-template '[& fns]
'(fn [payload] (-> payload fns))
'[fna fnb])
;; returns (fn [payload] (-> payload fnb))
I am surprised by the output, as I was expecting:
(fn [payload] (-> payload fna fnb))
Why is it producing this output, and what would be a way to achieve the above? I specifically says in the doc:
argv is an argument list, as in defn.
Note: it could be written like so, but I am trying to understand how to use template:
(defmacro wrap-fn-> [& fns]
`(fn [~'x#]
(-> ~'x
~@fns)))
templatebecause you hope it will be useful, don't bother. It is not used in real life outside of clojure.test, and it is a fairly limited tool; knowing how to write the macro yourself will serve you far better.