Function: `--pcase-macroexpander
`--pcase-macroexpander is a function defined in pcase.el.gz.
Signature
(`--pcase-macroexpander QPAT)
Documentation
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)
The predicate is the logical-AND of:
- Is EXPVAL a list of two elements?
- Is the first element the symbol technical?
- True! (The second element can be anything, and for the sake
of the body forms, its value is bound to the symbol forum.)
Source Code
;; Defined in /usr/src/emacs/lisp/emacs-lisp/pcase.el.gz
;; Closure converted to defun by helpful.
(defun \`--pcase-macroexpander
(qpat)
"Backquote-style pcase patterns: \\=`QPAT\nQPAT can take the following forms:\n (QPAT1 . QPAT2) matches if QPAT1 matches the car and QPAT2 the cdr.\n [QPAT1 QPAT2..QPATn] matches a vector of length n and QPAT1..QPATn match\n its 0..(n-1)th elements, respectively.\n ,PAT matches if the `pcase' pattern PAT matches.\n SYMBOL matches if EXPVAL is `equal' to SYMBOL.\n KEYWORD likewise for KEYWORD.\n NUMBER likewise for NUMBER.\n STRING likewise for STRING.\n\nThe list or vector QPAT is a template. The predicate formed\nby a backquote-style pattern is a combination of those\nformed by any sub-patterns, wrapped in a top-level condition:\nEXPVAL must be \"congruent\" with the template. For example:\n\n \\=`(technical ,forum)\n\nThe predicate is the logical-AND of:\n - Is EXPVAL a list of two elements?\n - Is the first element the symbol `technical'?\n - True! (The second element can be anything, and for the sake\n of the body forms, its value is bound to the symbol `forum'.)"
(cond
((eq
(car-safe qpat)
'\,)
(cadr qpat))
((vectorp qpat)
`(and
(pred vectorp)
(app length ,(length qpat))
,@(let
((upats nil))
(dotimes
(i
(length qpat))
(push
`(app
(pcase--flip aref ,i)
,(list '\`
(aref qpat i)))
upats))
(nreverse upats))))
((consp qpat)
`(and
(pred consp)
(app car-safe ,(list '\`
(car qpat)))
(app cdr-safe ,(list '\`
(cdr qpat)))))
((or
(stringp qpat)
(numberp qpat)
(symbolp qpat))
`',qpat)
(t
(error "Unknown QPAT: %S" qpat))))