I'm trying to pass a list to macro, for example:
(defmacro print-lst (lst)
`(progn
,@(mapcar #'(lambda (x) `(print ,x)) lst)))
(let ((lst '(1 2 3)))
(print-lst lst))
It caught error: "The value LST is not of type LST".
So, my question is, what's wrong with this piece of code and how to pass list to macro?
I'm not sure why you want to define this as a macro instead of a regular function, but the problem is that macros do not evaluate their arguments. If you give it the name of a lexical variable, all it sees is the name ('LST), not the bound value. It is complaining (correctly) that the symbol 'LST is not a list, and thus not a valid second argument to MAPCAR.
You could call it as (print-lst (1 2 3)), but then you could do without the macro and just do (mapc #'print lst)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With