[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?
- Re: Instead of pcase, Ihor Radchenko, 2024/01/01
- Re: Instead of pcase, Richard Stallman, 2024/01/02
- Re: Instead of pcase, Richard Stallman, 2024/01/02
- Re: Instead of pcase, Ihor Radchenko, 2024/01/03
- Re: Instead of pcase, Richard Stallman, 2024/01/04
- Re: Instead of pcase, Ihor Radchenko, 2024/01/06
- Re: Instead of pcase, Richard Stallman, 2024/01/07
- Re: Instead of pcase, Ihor Radchenko, 2024/01/08
- Re: Instead of pcase, Richard Stallman, 2024/01/26