std.lib.template

$

macro

added in 3.0

($ form)

template macro

(def -x- ’a)

($ (+ ~-x- 2 3)) => ’(+ a 2 3)

(let [a []] ($ (~@a))) => ()

(let a nil ($ (~@a))) => ()

*locals*

dynamic

deftemplate

macro

added in 3.0

(deftemplate & body)

marker for a template form

local-eval

added in 3.0

(local-eval form)(local-eval form locals)

evals local variables

(let x 1 (binding locals (template:locals) (local-eval ’(+ x x)))) => 2

replace-template

added in 3.0

(replace-template form args)

replace arguments with values

(replace-template ’(+ $0 $1 $2) ’x y z) => ’(+ x y z)

replace-unquotes

added in 3.0

(replace-unquotes form)

replace unquote and unquote splicing

(let x 1 (binding locals (template:locals) (replace-unquotes ’(+ ~x ~@(list x 1 2 3))))) => ’(+ 1 1 1 2 3)

template-fn

added in 3.0

(template-fn form)

replace body with template

(let -x- ’a (binding locals (template:locals) (template-fn ’(+ ~-x- 2 nil)))) => ’(+ a 2 nil)

template:locals

macro

added in 3.0

(template:locals)

gets local variable symbol names and values

(let x 1 y 2 (template:locals)) => ’{x 1, y 2}