Hello,
I want to create a macro that will have this expansion:
(qq my-op)
=>
(list 'my-op my-op)
This is not quite it, I think:
(defmacro qq (e)
(list 'list e (symbol-value e)))
It's "one level lower", if I could say that.
The greatest problem seems to be to quotify the argument of the macro.
TIA
Eli
On Mar 28, 7:58 pm, Eli Bendersky <······@gmail.com> wrote:
> Hello,
>
> I want to create a macro that will have this expansion:
>
> (qq my-op)
> =>
> (list 'my-op my-op)
>
> This is not quite it, I think:
>
> (defmacro qq (e)
> (list 'list e (symbol-value e)))
Here you are building a list at compile time, which would have these
elements:
* the symbol LIST;
* the value of E, which above will be the symbol MY-OP;
* and the symbol-value of the value of E, which is the symbol-value of
MY-OP, which I can't tell if it's bound or not.
This list [i.e. (list MY-OP value-of-MY-OP) ] will then be evaluated,
which will give you a list with these elements:
* value-of-MY-OP;
* value-of-value-of-MY-OP.
>
> It's "one level lower", if I could say that.
> The greatest problem seems to be to quotify the argument of the macro.
I think this is what you'd want:
(defmacro qq (e)
(list 'list (list 'quote e) e))
Which will (at compile time) result in a list with these elements:
* the symbol LIST
* the list (QUOTE MY-OP)
* the symbol MY-OP.
This list [i.e. (LIST (QUOTE MY-OP) MY-OP) ], when evaluated, would (I
hope), give what you want; a list with these elements:
* the symbol MY-OP;
* The value of MY-OP.
People use backquote (http://cl-cookbook.sourceforge.net/macros.html)
for this:
(defmacro qq (e)
`(list (quote ,e) ,e))
And then using ' for quote, we get:
(defmacro qq (e)
`(list ',e ,e))
>
> TIA
> Eli
HTH
Jonathan
Eli Bendersky wrote:
> Hello,
>
> I want to create a macro that will have this expansion:
>
> (qq my-op)
> =>
> (list 'my-op my-op)
>
> This is not quite it, I think:
>
> (defmacro qq (e)
> (list 'list e (symbol-value e)))
>
> It's "one level lower", if I could say that.
> The greatest problem seems to be to quotify the argument of the macro.
Untested:
(defmacro qq (e)
`(list ',e ,e))
kt
--
http://smuglispweeny.blogspot.com/
http://www.theoryyalgebra.com/
"In the morning, hear the Way;
in the evening, die content!"
-- Confucius