[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: pcase ` meaning [Was: Re: Replace trivial pcase occurrences in the E
From: |
Michael Heerdegen |
Subject: |
Re: pcase ` meaning [Was: Re: Replace trivial pcase occurrences in the Emacs sources] |
Date: |
Mon, 29 Oct 2018 22:33:10 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) |
"Garreau, Alexandre" <address@hidden> writes:
> Even in pcase I don’t see how to do that except manually using (and var
> (guard (equal var val))),
You mean like (pred (equal val))?
> #+begin_src emacs-lisp
> (pcase-defmacro list (&rest args)
> `(,'\` ,(mapcar (lambda (thing) `(,'\, ,thing)) args)))
> #+end_src
>
> I tried to adapt for arrays:
>
> #+begin_src emacs-lisp
> (pcase-defmacro array (&rest args)
> `[,'\` ,(mapcar (lambda (thing) `(,'\, ,thing)) args)])
> #+end_src
> But it doesn’t work x), that, plus my initial non-working
> “(pcase-defmacro list (&rest args) ``(,@args))”, I must find “`”, is,
> indeed, quite confusing (how is “,'” needed? how isn’t “,'\`” equivalent
> to “\`”?),
You want , to survive til after the macro expansion. Backquote can't
know that it should ignore a , because you want it to be literally in
the expansion. ,'\` let's backquote insert a literal , into the
expansion, which is what you want. The underlying problem is that you
want to use (of course you don't have to!) backquote to construct a
backquote expression. That happens here and there when writing Lisp,
it's not something special to pcase.
For understanding the definition above note that ``' (synonymous for
`backquote') is a (very normal) macro accepting one argument STRUCTURE,
whereby we also have an abbreviating reader syntax
`STRUCTURE == (` STRUCTURE). We also have the reader syntax
,THING == (, THING).
Your pcase macro `array' could be defined like
#+begin_src emacs-lisp
(pcase-defmacro array (&rest args)
`(,'\` [,@(mapcar (lambda (thing) `(,'\, ,thing)) args)]))
#+end_src
You could also write that without backquote (and also without the []
reader syntax).
Michael.
- Re: Replace trivial pcase occurrences in the Emacs sources, (continued)
- Re: Replace trivial pcase occurrences in the Emacs sources, Garreau\, Alexandre, 2018/10/27
- pcase ` meaning [Was: Re: Replace trivial pcase occurrences in the Emacs sources], Garreau\, Alexandre, 2018/10/27
- How other pattern-matching lisps do [Was: Re: pcase ` meaning [Was: Re: Replace trivial pcase occurrences in the Emacs sources]], Garreau\, Alexandre, 2018/10/28
- Re: How other pattern-matching lisps do [Was: Re: pcase ` meaning [Was: Re: Replace trivial pcase occurrences in the Emacs sources]], Stefan Monnier, 2018/10/28
- Re: How other pattern-matching lisps do [Was: Re: pcase ` meaning [Was: Re: Replace trivial pcase occurrences in the Emacs sources]], Garreau\, Alexandre, 2018/10/28
- Re: How other pattern-matching lisps do [Was: Re: pcase ` meaning [Was: Re: Replace trivial pcase occurrences in the Emacs sources]], Michael Heerdegen, 2018/10/28
- Re: pcase ` meaning [Was: Re: Replace trivial pcase occurrences in the Emacs sources], Michael Heerdegen, 2018/10/28
- Re: pcase ` meaning [Was: Re: Replace trivial pcase occurrences in the Emacs sources], Garreau\, Alexandre, 2018/10/28
- Re: pcase ` meaning [Was: Re: Replace trivial pcase occurrences in the Emacs sources], Michael Heerdegen, 2018/10/28
- Re: pcase ` meaning [Was: Re: Replace trivial pcase occurrences in the Emacs sources], Garreau\, Alexandre, 2018/10/29
- Re: pcase ` meaning [Was: Re: Replace trivial pcase occurrences in the Emacs sources],
Michael Heerdegen <=
- Re: pcase ` meaning, Garreau\, Alexandre, 2018/10/29
- Re: pcase ` meaning, Michael Heerdegen, 2018/10/29
- Re: pcase ` meaning, Garreau\, Alexandre, 2018/10/29
- Re: pcase ` meaning, Michael Heerdegen, 2018/10/29
- Re: pcase ` meaning, Yuri Khan, 2018/10/30
- Re: pcase ` meaning [Was: Re: Replace trivial pcase occurrences in the Emacs sources], Clément Pit-Claudel, 2018/10/29
- Re: pcase ` meaning, Garreau\, Alexandre, 2018/10/29
- Re: pcase ` meaning, Stefan Monnier, 2018/10/30
- Re: pcase ` meaning, Garreau\, Alexandre, 2018/10/31
- Re: Replace trivial pcase occurrences in the Emacs sources, Eli Zaretskii, 2018/10/28