From: Eli Bendersky
Subject: A macro that quotifies its argument
Date: 
Message-ID: <a7b5f71e-a7d2-4f7f-b87f-df616aa8d153@y21g2000hsf.googlegroups.com>
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

From: ···········@gmail.com
Subject: Re: A macro that quotifies its argument
Date: 
Message-ID: <7926b28e-1fe6-4d06-a438-03790b3fe98c@u10g2000prn.googlegroups.com>
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
From: Ken Tilton
Subject: Re: A macro that quotifies its argument
Date: 
Message-ID: <47ecc507$0$15206$607ed4bc@cv.net>
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
From: Eli Bendersky
Subject: Re: A macro that quotifies its argument
Date: 
Message-ID: <8af3775c-05b8-47ec-aeba-fb1df3158385@d21g2000prf.googlegroups.com>
> Untested:
>
> (defmacro qq (e)
>     `(list ',e ,e))
>

This works, thanks.
Also, Johnathan - thanks for the detailed explanation.

Eli