help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: macro-replacement with quotes


From: Michael Heerdegen
Subject: Re: macro-replacement with quotes
Date: Mon, 25 Jan 2016 15:35:38 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

phillip.lord@russet.org.uk (Phillip Lord) writes:

> It's a thought, so I tried this....
>
> (defmacro p-test-2 (var)
>   `(pcase 10
>      ('`(,var) ,var)))
>
>
> but this fails because the ' quotes the ` and the list following it. So
> you get:
>
> (p-test-2 a)
>
> expands
>
> (pcase 10
>   ('`(,var)
>    a))
>
> It's all very complicated isn't it?

It is indeed.

The problem here is that you cant even combine backquote, quote and
unquote like e.g. in macro definitions where you see things like

  ,',var

because the ` in pcase patterns is never expanded by the backquote
macro.

My standard solution to such situations is to use the long forms

 (, thing), (` thing)

and to paste in with , the quoted , or `, so that at the end, you have
what you want (just ` and ,).  That looks like this in your example:

(defmacro p-test-2 (var)
  `(pcase 10
     ((,'\` ((,'\, ,var))) ,var)))

(macroexpand-1 '(p-test-2 a))

==>

(pcase 10
  (`(,a) a))


(hoping this is what you wanted).

I wonder if there is a more elegant solution...


Regards,

Michael.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]