emacs-devel
[Top][All Lists]
Advanced

[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: Sun, 28 Oct 2018 23:54:00 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

"Garreau, Alexandre" <address@hidden> writes:
> So know I understand why advocating for replacing case with pcase: pcase
> is not about pattern matching, it is just a correctly working case,
> except it only works for atoms, with an optional prevailing
> mini-language

If you look at the definition of the ``' pcase macro you see that it is
defined entirely in terms of the "things that only work for atoms" (it
uses `app' on car and cdr).

> Maybe that would make more sense if ` (and '?) were not part of pcase’s
> own mini-language, redefined by pcase, but if pcase actually truly
> eval’d its pattern, defining pred, guard, etc. as real functions,
> defined with a cl-letf, using lexical scoping so to prevailably define
> all these + user-defined patterns.

I think it would also be an interesting approach.  You would
additionally need some magical thing that binds variables for the scope
of the current clause, however.  That doesn't fit into that simple
approach.  But not less than into pcase itself.

I wonder if it could be similarly efficient as pcase.

> It even more feel wrong that, this, doesn’t work, for no reason

Well, there is a reason: it is wrong ;-)

> #+BEGIN_SRC emacs-lisp
>   (pcase [1 2]
>     ([a b] (+ a b)))
> #+END_SRC

That should be 

#+begin_src emacs-lisp
(pcase [1 2]
  (`[,a ,b] (+ a b)))
#+end_src

I'm sure you would have been able to find that after less than a minute
when reading the pcase docstring.


Michael.



reply via email to

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