Macro
Expands to a fn using _1, _2, _3, etc. as arguments (_ is the same as _1). Any sub-expressions without any _* variables are evaluated when the fn is created, not when it is called.
; clojure/contrib/template.clj:152 (defmacro template [& form] (when-not (template? form) (throw (IllegalArgumentException. (str (pr-str form) " is not a valid template.")))) (let [form (postwalk-replace {'_ '_1} form) holes (find-holes form) pures (find-pure-exprs form) smap (zipmap pures (repeatedly #(gensym "HOLE_"))) newform (prewalk-replace smap form) ;; Now, make sure we omit nested sub-expressions: used (set (filter #(.startsWith (name %) "HOLE_") (find-symbols newform))) newmap (reduce (fn [m [k v]] (if (used v) (assoc m k v) m)) {} smap)] `(let ~(flatten-map (clojure.set/map-invert newmap)) (fn ~(vec holes) ~@newform))))
Copyright (c) Rich Hickey. All rights reserved.
The use and distribution terms for this software are covered by the Eclipse Public License 1.0, which can be found in the file epl-v10.html at the root of this distribution. By using this software in any fashion, you are agreeing to be bound by the terms of this license. You must not remove this notice, or any other, from this software.