Replaces _1, _2, _3, etc. in expr with corresponding elements of
values. Returns the modified expression. For use in macros.
(defn apply-template
"Replaces _1, _2, _3, etc. in expr with corresponding elements of
values. Returns the modified expression. For use in macros."
[expr values]
(when-not (template? expr)
(throw (IllegalArgumentException. (str (pr-str expr) " is not a valid template."))))
(let [expr (walk/postwalk-replace {'_ '_1} expr)
holes (find-holes expr)
smap (zipmap holes values)]
(walk/prewalk-replace smap expr)))
Comments top
No comments for apply-template. Log in to add a comment.