I'm learning the macro system of Common Lisp and suddenly found a problem
(defun hello () (format t "hello ~%"))
(defun world () (format t "world ~%"))
(defmacro call-2-func (func1 func2)
`(,func1)
`(,func2))
(macroexpand-1 '(call-2-func hello world))
(WORLD)
T
Well. Why can't I generate 2 LoC from only one macro? How can I work around? (progn will not work in a more complicated situation...)
Your macro needs to return just one form that will call both functions.
Instead you are generating two forms (and only the last one is used.)
Try:
(defmacro call-2-func (func1 func2)
`(progn (,func1) (,func2)))
or if you do not want to be limited to just 2 functions:
(defmacro call-funcs (&rest funcs)
`(progn ,@(mapcar #'list funcs)))
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