Define a macro that expands into forms after replacing the
symbols in params (a vector) by the corresponding parameters
given in the macro call.
(defmacro deftemplate
"Define a macro that expands into forms after replacing the
symbols in params (a vector) by the corresponding parameters
given in the macro call."
[name params & forms]
(let [param-map (for [p params] (list (list 'quote p) (gensym)))
template-params (vec (map second param-map))
param-map (vec (apply concat param-map))
expansion (list 'list (list 'quote `symbol-macrolet) param-map
(list 'quote (cons 'do forms)))]
`(defmacro ~name ~template-params ~expansion)))
Comments top
No comments for deftemplate. Log in to add a comment.