You're viewing version 1.2.0 of do-template. The latest stable version of Clojure Core is 1.3.0.
1.2.0 Arrow_down_16x16

do-template

clojure.template

  • (do-template argv expr & values)
Repeatedly copies expr (in a do block) for each group of arguments
in values. values are automatically partitioned by the number of
arguments in argv, an argument vector as in defn.

Example: (macroexpand '(do-template [x y] (+ y x) 2 4 3 5))
;=> (do (+ 4 2) (+ 5 3))

1 Example top

  • ;; Because it is expanded at compile time, you can also use special 
    ;; forms as in full blown macros:
    
    user=> (use 'clojure.template)
    user=> (do-template [a b] (def a b) d 1 e 2 f 3)
    #'user/f
    user=> d
    1
    user=> e
    2
    user=> f
    3
    
    ;; and if you are curious why
    user=> (use 'clojure.walk)
    user=> (macroexpand-all '(do-template [a b] (def a b) d 1 e 2 f 3))
    (do (def d 1) (def e 2) (def f 3))
    
    
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/template.clj:45 top

(defmacro do-template
  "Repeatedly copies expr (in a do block) for each group of arguments
  in values.  values are automatically partitioned by the number of
  arguments in argv, an argument vector as in defn.

  Example: (macroexpand '(do-template [x y] (+ y x) 2 4 3 5))
           ;=> (do (+ 4 2) (+ 5 3))"
  [argv expr & values]
  (let [c (count argv)]
    `(do ~@(map (fn [a] (apply-template argv expr a)) 
                (partition c values)))))
Vars in clojure.template/do-template: defmacro fn let map partition concat list seq
Used in 0 other vars

Comments top

No comments for do-template. Log in to add a comment.