emacs-devel
[Top][All Lists]
Advanced

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

Re: pcase ` meaning


From: Garreau\, Alexandre
Subject: Re: pcase ` meaning
Date: Tue, 30 Oct 2018 00:00:24 +0100
User-agent: Gnus (5.13), GNU Emacs 25.1.1 (i686-pc-linux-gnu, GTK+ Version 3.22.11) of 2017-09-15, modified by Debian

Le 29/10/2018 à 22h33, Michael Heerdegen a écrit :
> "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))?

Oh indeed!  Still that defeat the purpose of pattern matching by
requiring non-pattern matching stuff.

>> #+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.

Yes I know, what I meant is `, in lisp, can generally lead to confusion
unexperimented programmer.  That’s one of the selling points of hygienic
macros (standard and default in scheme).

The fact pcase is not strictly treating ` as standard lisp’s reader does
is only *adding* the the already existing confusion normal and standard
` introduces in lisp.

> 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).

Indeed you’re right, but that doesn’t automagically explain to me how
does exactely work the “,” macro, as it stays context dependant, not
trivial, and to me, “,” meant either “eval” or “undo ‘`’” (the later is
nearer to the meaning used in pcase btw).

> 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).

Ah okkkk!  Backquotes may be difficult or confusing to master fully, but
at least they’re consistent and simple enough to stay readable, I find,
more easily than easily writable.



reply via email to

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