all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* A protest against pcase, pcase-let, pcase-let*
@ 2015-03-31 18:00 Alan Mackenzie
  2015-03-31 18:29 ` John Wiegley
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Alan Mackenzie @ 2015-03-31 18:00 UTC (permalink / raw)
  To: emacs-devel

Hello, Emacs.

Can we please have a moratorium on the use of pcase, etc.?  Their use is
gradually proliferating through Emacs, yet they are not documented.

OK, maybe pcase itself has a page in the elisp manual, but this page is
very difficult to understand, certainly for me.  I have attempted quite
a lot of times to make sense of it, and failed.

There are two possibilities here: (i) the page is difficult because
pcase is itself difficult.  In this case we should stop using pcase and
systematically remove it from Emacs source.  (ii) The page is difficult
because it is not well written.  In this case it should be improved.
Personally, I think (ii) is more likely to be true than (i).

pcase-let and pcase-let* are totally absent from the elisp manual.
Their doc strings say nothing more than "Like `let' but where you can
use `pcase' patterns for bindings.", without giving any clue as to what
"`pcase' patterns" are, or what the syntax and semantics of their
"use" of them for bindings look like.

Recently, jit-lock.el was changed to include a pcase-let and a
pcase-let*.  The pertinent code is, to me, completely obscure.  As these
forms encroach on an ever increasing portion of Emacs, the part of Emacs
in which I can usefully hack diminishes correspondingly.  I suspect I am
not alone here.

As an aside, I suspect that edebug will not be useful in (possibly
large) uses of these forms, given that they are implemented as macros
rather than special forms.

Could we have a moratorium on further use of these three forms until the
above issues have been resolved?

-- 
Alan Mackenzie (Nuremberg, Germany).



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: A protest against pcase, pcase-let, pcase-let*
  2015-03-31 18:00 A protest against pcase, pcase-let, pcase-let* Alan Mackenzie
@ 2015-03-31 18:29 ` John Wiegley
  2015-04-18  1:47   ` Ted Zlatanov
  2015-03-31 19:25 ` Dmitry Gutov
  2015-04-01  9:59 ` Phillip Lord
  2 siblings, 1 reply; 10+ messages in thread
From: John Wiegley @ 2015-03-31 18:29 UTC (permalink / raw)
  To: emacs-devel

>>>>> Alan Mackenzie <acm@muc.de> writes:

> Can we please have a moratorium on the use of pcase, etc.?  Their use is
> gradually proliferating through Emacs, yet they are not documented.

-1 from me.  It may not be well documented, but it's certainly useful for
package authors.  Should we be restricted because others are having difficulty
figuring out how to use them?

John



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: A protest against pcase, pcase-let, pcase-let*
  2015-03-31 18:00 A protest against pcase, pcase-let, pcase-let* Alan Mackenzie
  2015-03-31 18:29 ` John Wiegley
@ 2015-03-31 19:25 ` Dmitry Gutov
  2015-04-01  7:46   ` Daniel Colascione
  2015-04-01  9:59 ` Phillip Lord
  2 siblings, 1 reply; 10+ messages in thread
From: Dmitry Gutov @ 2015-03-31 19:25 UTC (permalink / raw)
  To: Alan Mackenzie, emacs-devel

On 03/31/2015 09:00 PM, Alan Mackenzie wrote:

> OK, maybe pcase itself has a page in the elisp manual, but this page is
> very difficult to understand, certainly for me.  I have attempted quite
> a lot of times to make sense of it, and failed.

I think it's pretty nice. It provides pattern matching, as well as 
destructuring (something that previously required the use of cl-lib), in 
a concise and performant way.

The docs can look a bit dense at first, but after reading them carefully 
and experimenting a bit, I'm sure most people can get a hang of it.

> There are two possibilities here: (i) the page is difficult because
> pcase is itself difficult.

It's not trivial. Pattern matching is, usually, a feature of more 
advanced programming languages. But that doesn't mean we shouldn't use it.

> pcase-let and pcase-let* are totally absent from the elisp manual.
> Their doc strings say nothing more than "Like `let' but where you can
> use `pcase' patterns for bindings.", without giving any clue as to what
> "`pcase' patterns" are, or what the syntax and semantics of their
> "use" of them for bindings look like.

`pcase' patterns are described in the `pcase' docstring, and in the 
manual entry for it.

The semantics of use of them for bindings should be pretty apparent 
after you understand how to use `pcase' itself.

> As an aside, I suspect that edebug will not be useful in (possibly
> large) uses of these forms, given that they are implemented as macros
> rather than special forms.

It worked well when I tried it.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: A protest against pcase, pcase-let, pcase-let*
  2015-03-31 19:25 ` Dmitry Gutov
@ 2015-04-01  7:46   ` Daniel Colascione
  0 siblings, 0 replies; 10+ messages in thread
From: Daniel Colascione @ 2015-04-01  7:46 UTC (permalink / raw)
  To: Dmitry Gutov, Alan Mackenzie, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 811 bytes --]

On 03/31/2015 12:25 PM, Dmitry Gutov wrote:
> On 03/31/2015 09:00 PM, Alan Mackenzie wrote:
> 
>> OK, maybe pcase itself has a page in the elisp manual, but this page is
>> very difficult to understand, certainly for me.  I have attempted quite
>> a lot of times to make sense of it, and failed.
> 
> I think it's pretty nice. It provides pattern matching, as well as
> destructuring (something that previously required the use of cl-lib), in
> a concise and performant way.
> 
> The docs can look a bit dense at first, but after reading them carefully
> and experimenting a bit, I'm sure most people can get a hang of it.

pcase is really an excellent tool. The documentation is better for
reference than for learning how to use it, though. Good thing Emacs is
full of pcase examples now.



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: A protest against pcase, pcase-let, pcase-let*
  2015-03-31 18:00 A protest against pcase, pcase-let, pcase-let* Alan Mackenzie
  2015-03-31 18:29 ` John Wiegley
  2015-03-31 19:25 ` Dmitry Gutov
@ 2015-04-01  9:59 ` Phillip Lord
  2015-04-01 12:04   ` Nic Ferrier
  2015-04-02  7:19   ` Richard Stallman
  2 siblings, 2 replies; 10+ messages in thread
From: Phillip Lord @ 2015-04-01  9:59 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: emacs-devel



Alan Mackenzie <acm@muc.de> writes:
> Can we please have a moratorium on the use of pcase, etc.?  Their use is
> gradually proliferating through Emacs, yet they are not documented.
>
> OK, maybe pcase itself has a page in the elisp manual, but this page is
> very difficult to understand, certainly for me.  I have attempted quite
> a lot of times to make sense of it, and failed.
>
> There are two possibilities here: (i) the page is difficult because
> pcase is itself difficult.  In this case we should stop using pcase and
> systematically remove it from Emacs source.  (ii) The page is difficult
> because it is not well written.  In this case it should be improved.
> Personally, I think (ii) is more likely to be true than (i).


The documentation is, I think, written from the perspective of someone
who knows what this sort of pattern-matching does already. The elisp
manual is, of course, a manual rather than a tutorial and the pcase
documentation is particularly not an easy read.

The emacs-wiki has tons of examples, which is much easier to understand
I think!

http://www.emacswiki.org/emacs/PatternMatching



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: A protest against pcase, pcase-let, pcase-let*
  2015-04-01  9:59 ` Phillip Lord
@ 2015-04-01 12:04   ` Nic Ferrier
  2015-04-01 12:16     ` Dmitry Gutov
  2015-04-01 13:53     ` Stefan Monnier
  2015-04-02  7:19   ` Richard Stallman
  1 sibling, 2 replies; 10+ messages in thread
From: Nic Ferrier @ 2015-04-01 12:04 UTC (permalink / raw)
  To: Phillip Lord; +Cc: Alan Mackenzie, emacs-devel

phillip.lord@newcastle.ac.uk (Phillip Lord) writes:

> The documentation is, I think, written from the perspective of someone
> who knows what this sort of pattern-matching does already. The elisp
> manual is, of course, a manual rather than a tutorial and the pcase
> documentation is particularly not an easy read.
>
> The emacs-wiki has tons of examples, which is much easier to understand
> I think!
>
> http://www.emacswiki.org/emacs/PatternMatching

I think it's awful, personally.

I don't recall any discussion about whether it would be useful
either. Unlike for, say, the yield stuff which has to be debated
forever.

There are much better, more lisp idiomatic, libs for doing pattern
matching which pcase should give way to imo.

Shadchen for example.


Pattern matching is an excellent tool for programmers. I think pcase is
a poor implementation for EmacsLisp.


Nic



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: A protest against pcase, pcase-let, pcase-let*
  2015-04-01 12:04   ` Nic Ferrier
@ 2015-04-01 12:16     ` Dmitry Gutov
  2015-04-01 13:53     ` Stefan Monnier
  1 sibling, 0 replies; 10+ messages in thread
From: Dmitry Gutov @ 2015-04-01 12:16 UTC (permalink / raw)
  To: Nic Ferrier, Phillip Lord; +Cc: Alan Mackenzie, emacs-devel

On 04/01/2015 03:04 PM, Nic Ferrier wrote:

> I think it's awful, personally.

That's a strong statement to make without specific arguments.

> I don't recall any discussion about whether it would be useful
> either. Unlike for, say, the yield stuff which has to be debated
> forever.

pcase is years old, and nobody has proposed an alternative yet.

> There are much better, more lisp idiomatic, libs for doing pattern
> matching which pcase should give way to imo.
>
> Shadchen for example.

Your case would be stronger is Shadchen was at least in GNU ELPA.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: A protest against pcase, pcase-let, pcase-let*
  2015-04-01 12:04   ` Nic Ferrier
  2015-04-01 12:16     ` Dmitry Gutov
@ 2015-04-01 13:53     ` Stefan Monnier
  1 sibling, 0 replies; 10+ messages in thread
From: Stefan Monnier @ 2015-04-01 13:53 UTC (permalink / raw)
  To: Nic Ferrier; +Cc: Alan Mackenzie, Phillip Lord, emacs-devel

> There are much better, more lisp idiomatic, libs for doing pattern
> matching which pcase should give way to imo.

> Shadchen for example.

I don't see much difference.  AFAICT if there's a particular pattern of
shadchen you like, you/we can add it to pcase with `pcase-defmacro' and
IIUC both sets of patterns are perfectly compatible (and very similar
in spirit).
You can also add any of pcase's patterns to shadchen via its
defpattern construct, AFAICT).

It differs in implementation technique, tho, since AFAICT in shadchen

   (match X
     ((cons 1 a) (foo1))
     ((cons 2 a) (foo2)))

will tests `listp' twice and will extract the car of X twice (i.e. it
does not optimize the second branch based on the knowledge of how the
first branch's pattern failed to match).

I guess the main difference you'll see is that shadchen supports
backquote via `bq' and `uq' rather than via ` and , so

   (pcase X
     (`(1 . ,a) (foo1))
     (`(2 . ,a) (foo2)))

turns into

   (match X
    ((bq (1 (uq a))) (foo1))
    ((bq (2 (uq a))) (foo2)))

which is so hideous that noone will ever use it.  IIUC you don't like
the backquote syntax in patterns, so shadchen making it even more
hideous than it already is suits you better.


        Stefan



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: A protest against pcase, pcase-let, pcase-let*
  2015-04-01  9:59 ` Phillip Lord
  2015-04-01 12:04   ` Nic Ferrier
@ 2015-04-02  7:19   ` Richard Stallman
  1 sibling, 0 replies; 10+ messages in thread
From: Richard Stallman @ 2015-04-02  7:19 UTC (permalink / raw)
  To: Phillip Lord; +Cc: acm, emacs-devel

[[[ To any NSA and FBI agents reading my email: please consider    ]]]
[[[ whether defending the US Constitution against all enemies,     ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]

Since pcase is not described in the Intro to Emacs Lisp Programming,
its documentation in the Lisp Reference Manual needs to be clear
enough to make sense to someone who does not know about it.

Would people please work on improving it?

-- 
Dr Richard Stallman
President, Free Software Foundation
51 Franklin St
Boston MA 02110
USA
www.fsf.org  www.gnu.org
Skype: No way! See stallman.org/skype.html.




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: A protest against pcase, pcase-let, pcase-let*
  2015-03-31 18:29 ` John Wiegley
@ 2015-04-18  1:47   ` Ted Zlatanov
  0 siblings, 0 replies; 10+ messages in thread
From: Ted Zlatanov @ 2015-04-18  1:47 UTC (permalink / raw)
  To: emacs-devel

On Tue, 31 Mar 2015 13:29:20 -0500 "John Wiegley" <johnw@newartisans.com> wrote: 

>>>>>> Alan Mackenzie <acm@muc.de> writes:
>> Can we please have a moratorium on the use of pcase, etc.?  Their use is
>> gradually proliferating through Emacs, yet they are not documented.

JW> -1 from me.  It may not be well documented, but it's certainly useful for
JW> package authors.  Should we be restricted because others are having difficulty
JW> figuring out how to use them?

Like John, I would prefer to keep using pcase.  I'm a fan of the tool.

I would love the manual to dedicate more space to it, and feel that I've
only grazed the surface. Perhaps a whole chapter, since pcase
(understandably) departs from so many of the typical Emacs programming
patterns. And that chapter can mention Shadchen and whatever else is
pertinent.

Ted




^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2015-04-18  1:47 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-31 18:00 A protest against pcase, pcase-let, pcase-let* Alan Mackenzie
2015-03-31 18:29 ` John Wiegley
2015-04-18  1:47   ` Ted Zlatanov
2015-03-31 19:25 ` Dmitry Gutov
2015-04-01  7:46   ` Daniel Colascione
2015-04-01  9:59 ` Phillip Lord
2015-04-01 12:04   ` Nic Ferrier
2015-04-01 12:16     ` Dmitry Gutov
2015-04-01 13:53     ` Stefan Monnier
2015-04-02  7:19   ` Richard Stallman

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.