I want a macro my-macro
which can expand to 1 2 3
rather than (1 2 3)
, so that
(list (my-macro) 4 5) -> (1 2 3 4 5)
Is this possible?
I want a macro my-macro
which can expand to 1 2 3
rather than (1 2 3)
, so that
(list (my-macro) 4 5) -> (1 2 3 4 5)
Is this possible?
No.
Neither a macro nor a read macro can do that in Common Lisp.
The only solution if you really need this is to write a full reader yourself where you don't use
read
at all (the problem is thatread
will recursively call itself, and not your version).A full compliant reader is quite a complex thing to do, but it can be simple if you only need a subset of the features and you don't need to use it for example to read Common Lisp code written by others.
No, macros cannot expand to more than one value. The typical thing to do when you need a macro to expand to multiple pieces of code is to wrap the return value in a
progn
.In your example in the comments, it looks as if you are using macros not as syntactic abstractions, but as cheap-and-cheerful function optimizations, the usual response to that is "please don't do it, it is wrong and doesn't actually do what you want".