[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Instead of pcase
From: |
Philip Kaludercic |
Subject: |
Re: Instead of pcase |
Date: |
Thu, 16 Nov 2023 18:47:48 +0000 |
"T.V Raman" <raman@google.com> writes:
> when-let let-alist etc have worked well for me.
>
> What threw me with pcase is there are lots of special chars in that
> particular example whose meaning I dont know, and looking those up and
> understanding their use at the same time was what chased me away
Taking the concrete example you mentioned,
(pcase res
(`(,_ . ,(and (pred functionp) f)) (funcall f))
(`(,hookfun . (,start ,end ,collection . ,plist))
the unknown or unfamiliar characters are "`" and ",". The (dynamic)
pcase documentation string is pretty straightforward in explaining what
it does, or can you recall what confused you?:
--8<---------------cut here---------------start------------->8---
-- `QPAT
Backquote-style pcase patterns: `QPAT
QPAT can take the following forms:
(QPAT1 . QPAT2) matches if QPAT1 matches the car and QPAT2 the cdr.
[QPAT1 QPAT2..QPATn] matches a vector of length n and QPAT1..QPATn match
its 0..(n-1)th elements, respectively.
,PAT matches if the ‘pcase’ pattern PAT matches.
SYMBOL matches if EXPVAL is ‘equal’ to SYMBOL.
KEYWORD likewise for KEYWORD.
NUMBER likewise for NUMBER.
STRING likewise for STRING.
The list or vector QPAT is a template. The predicate formed
by a backquote-style pattern is a combination of those
formed by any sub-patterns, wrapped in a top-level condition:
EXPVAL must be "congruent" with the template. For example:
`(technical ,forum)
--8<---------------cut here---------------end--------------->8---
Or if you mean "_", then
--8<---------------cut here---------------start------------->8---
PATTERN can take one of the forms:
_ matches anything.
--8<---------------cut here---------------end--------------->8---
which is familiar to people coming from functional languages, but even
Elisp uses underscores to denote unused variables.
- Re: Instead of pcase, (continued)
- Re: Instead of pcase, Dmitry Gutov, 2023/11/16
- Re: Instead of pcase, T.V Raman, 2023/11/16
- Re: Instead of pcase,
Philip Kaludercic <=
- Re: Instead of pcase, T.V Raman, 2023/11/16
- Re: Instead of pcase, Richard Stallman, 2023/11/17
- Re: Instead of pcase, Michael Heerdegen, 2023/11/19
- Re: Instead of pcase, Barry Fishman, 2023/11/19
- Re: Instead of pcase, Dmitry Gutov, 2023/11/19
- Re: Instead of pcase, Eric Abrahamsen, 2023/11/19
- Re: Instead of pcase, Stefan Monnier, 2023/11/24
- Re: Instead of pcase, Richard Stallman, 2023/11/26
- Re: Instead of pcase, Barry Fishman, 2023/11/19
- Re: Instead of pcase, Dmitry Gutov, 2023/11/19