emacs-devel
[Top][All Lists]
Advanced

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

Re: Instead of pcase


From: Eli Zaretskii
Subject: Re: Instead of pcase
Date: Fri, 01 Dec 2023 13:52:21 +0200

> From: João Távora <joaotavora@gmail.com>
> Date: Fri, 1 Dec 2023 10:02:37 +0000
> Cc: owinebar@gmail.com, rms@gnu.org, dmitry@gutov.dev, philipk@posteo.net, 
>       emacs-devel@gnu.org
> 
> On Fri, Dec 1, 2023 at 6:31 AM Eli Zaretskii <eliz@gnu.org> wrote:
> 
> So, in these emails, I'm trying to explain to you how to change your
> view of these pcase constructs in a constructive way

This is a misunderstanding: I'm not expressing _my_ views.  I'm
expressing the views of someone who bumps into this code the first or
the second time, and/or didn't yet have the advantage of someone
giving them "a piece of insight" that caused you to change your mind.
IOW, I'm expressing _your_ views before you changed your mind.

In Emacs development and maintenance, being able to look at stuff from
the POV of an innocent user or Lisp programmer is sometimes required
to realize the true impact of some constructs and features.  We cannot
regard that only from the height of our own knowledge and experience,
which usually far surpass those of many Emacs users and programmers.

> You take a backtick-starting construct with as many scary periods
> things as you can find and then, say
> 
> `(,foo . (,bar . ,baz))
> 
> And then ask yourself: "what kind of list does this build if I just
> let-bind foo, bar and baz to 42?". And then you answer yourself
> "Why, it's the improper list (42 42 . 42) made up of just two cons
> cells and 3 fixnums!".  So _that's_ the kind of list that can be
> destructured with the pcase expression.
> 
> This solves the reading problem.  Now the writing problem. To author
> new pcase patterns one uses more or less the same process.  One again
> leans on one's existing knowledge of how the list structure would be
> expressed with backtick-and-quote.  So once you know the list
> structure in your mind you write it as a backtick-and-quote expression,
> just as if you were going to craft that list (though you aren't of
> course).  Then once you're happy with your expression, you may take it
> and you put it in one of the BINDINGS left-hand part of a 'let'.
> Then you rename that 'let' to 'pcase-let' and away you go!

If this is that easy, then why do we need no less than 120 lines to
describe pcase in the doc string, and no less than 600 lines to
document its features in the ELisp manual?

You and others seem to assume that I'm against pcase, or that I'm
attacking its syntax, or don't understand it.  Andreas Schwab has even
gone as far as lecture me on the basics of the Lisp reader and the
syntax of Emacs Lisp, apparently under the assumption that I don't
understand that.  None of that is true.  All I'm trying to say is that
there _are_ inherent problems in the DSL whose knowledge is required
to understand code written using pcase, and that you and others should
recognize these inherent problems are real, even though you have
overcome them, and anyone could overcome them given enough time and
experience.



reply via email to

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