emacs-devel
[Top][All Lists]
Advanced

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

Re: Instead of pcase


From: Stefan Kangas
Subject: Re: Instead of pcase
Date: Mon, 8 Jan 2024 21:33:43 -0800

João Távora <joaotavora@gmail.com> writes:

> It is _easy_ to explain that "scary" construct _if_ you learn to _lean_
> on what should be probably existing knowledge.  No doc-consulting
> necessary.
>
> 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!

Could you reformat this as a documentation patch?



reply via email to

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