[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Instead of pcase
From: |
Alan Mackenzie |
Subject: |
Re: Instead of pcase |
Date: |
Fri, 1 Dec 2023 20:27:50 +0000 |
Hello, Michael
On Fri, Dec 01, 2023 at 16:47:51 +0100, Michael Heerdegen via Emacs development
discussions. wrote:
> Eli Zaretskii <eliz@gnu.org> writes:
> > > This is not a valid expression and will be rejected by the reader.
> > > Was it a typo or did you think this would be valid?
> > It was taken from one of the posted examples, perhaps with a typo.
> > But that is not relevant.
> My question was meant sincerely. Did you try to understand the syntax?
> How? What was or is still unclear to you?
> > Are you saying pcase doesn't have
> > constructs like (`(SOMETHING...), or that SOMETHING doesn't use
> > periods in places where they are redundant in "normal" ELisp code?
> Redundant - no. May there be different redundant ways to express lists
> - yes.
> If you use a backquote pattern `SOMETHING in pcase, when SOMETHING
> should match a cons (lists are conses), then SOMETHING will typically be
> a cons. The dot reader syntax is the canonical read syntax for conses.
> This is not that weird.
For some reason, I have little difficulty with dots in normal code, but
have more difficulty with dots in pcase patterns. They must be being
used differently.
> > IOW, these details are not the point, the point is something else
> > entirely, see below [...]
> > My point focuses on the problems this syntax causes to someone who
> > doesn't have intimate knowledge and a lot of practice with pcase.
> It is repeatedly used a wording like "magical", as if that was an
> argument. Ok, this syntax makes one first wonder how it has to be
> interpreted. Happened to me, too. But this (the wondering) takes only
> seconds.
It took many hours for me.
> What happens after that? Have people then seriously tried to
> understand the syntax? Where and why did they fail? I heard nothing
> about that. Just a repetition that it looks "strange" or "magical" or
> that one would expect a different syntax.
The syntax is confusing. Before the introduction of pcase (without any
public discussion, as far as I can remember) a backslash meant what it
meant, as did a comma. Now, if there are pcase's around I can't look at
code and see what it means. For each backslash or comma, I've
consciously got to stop and inspect it to see whether it's a standard b
or c, or a pcase b or c. They tend to be mixed up indiscriminately.
Also, special forms which had a fixed meaning have now become ambiguous -
and and or. Again, it takes conscious inspection to determine whether
one of these has its standard meaning, or the very different pcase
meaning.
> Given that cons cells and lists are fundamental building blocks of the
> whole language, I had hoped to hear more about why understanding this
> would be hard. Nobody did that concretely apart from Richard. And it
> might be the case that his rewrite will reuse the backquote syntax.
See my previous paragraphs for part of the problem.
> > > As an alternative one can have a look at the docstring.
> > It is a disadvantage if one needs to consult doc strings all the time
> > while reading code. And in this case, the doc string is quite long
> > and highly non-trivial (and rightfully so, since the DSL is a rather
> > complex one).
> This is, or should, not be the case. Sometimes one might need to recall
> the argument order of 'let' or 'app', but more when writing code.
> I don't ever need to consult the documentation of `pcase' when reading
> code, apart from the case when additional pcase macros are involved
> (like 'map'). And I don't have a good such a good memory for such
> things.
I don't have a good memory for them, either. When I have to read code
with pcase stuff in it, I can't read it fluently. My consciousness is
continually having to guess what the various constructs mean, which is
demoralising. I don't have this problem with non-pcase code which is
otherwise of the same difficulty.
> And I use it only in rare circumstances, where possible I prefer `if',
> `cond', and `if-let'.
I only use it when maintaining other people's code.
> > If one bumps into such constructs very frequently, then eventually one
> > will become familiarized with them. But if the frequency is low
> > enough, one could easily forget the details, and then one will need to
> > consult the documentation again the next time.
> What I want to say is that if you need to consult documentation of
> backquote syntax in pcase again and again, you might not have understood
> it entirely. This is my question: do people fail to understand the
> concept, or don't they even try?
It's not the concept, it's the details. The documentation for pcase on
its own is probably bigger than that for all the standard Emacs Lisp flow
control constructs put together.
Another thing about pcase is that you can't usefully learn and use just
part of it. It's all or nothing, and it's a terrific effor to learn at
once. I don't recall anything like this difficulty learning, say,
regexps. It also contrasts with something like German adjective endings,
where one can usefully learn, say, just those for the three forms of
nominative and accusative, and gradually extend one's fluency, say, when
a dative ending becomes needed.
> > Please don't underestimate these difficulties, even if you don't share
> > them.
> I still try to understand them.
Yes. I hope I've done something to increase this understanding with this
post.
> Michael.
--
Alan Mackenzie (Nuremberg, Germany).
Re: Instead of pcase, Eli Zaretskii, 2023/12/01