avoiding eval in a macro
Posted: Fri Jan 06, 2012 1:09 pm
Hi there,
I'm not very deep into CL yet and struggling with this problem:
The following macro won't compile because ,@body is not a list (sbcl)
However if try a (listp ,body) it will return true. Can you please help me to understand this?
(the code is reduced beyond usefulness to show the problem)
TIA
murph
Of course I can use eval like this, but I want to avoid it
I'm not very deep into CL yet and struggling with this problem:
The following macro won't compile because ,@body is not a list (sbcl)
However if try a (listp ,body) it will return true. Can you please help me to understand this?
(the code is reduced beyond usefulness to show the problem)
TIA
murph
Code: Select all
(defmacro gen-name-broken (name)
(let ((body (intern "BODY")))
`(defmacro ,name (&body body)
(let ((result (progn ,@body)))
result))))
Code: Select all
(defmacro gen-name-eval (name)
(let ((body (intern "BODY")))
`(defmacro ,name (&body body)
(warn "is-list? ~S~%" (listp ,body))
(let ((result (apply #'eval ,body)))
result))))