## pcase

**pcase**is an autoloaded Lisp macro in `

`pcase.el`

'.(pcase

__EXP__&rest

__CASES__)

Perform ML-style pattern matching on

__EXP__.

__CASES__is a list of elements of the form (UPATTERN CODE...).

UPatterns can take the following forms:

_ matches anything.

SELFQUOTING matches itself. This includes keywords, numbers, and strings.

SYMBOL matches anything and binds it to SYMBOL.

(or UPAT...) matches if any of the patterns matches.

(and UPAT...) matches if all the patterns match.

'VAL matches if the object is `equal' to VAL

`QPAT matches if the QPattern QPAT matches.

(pred FUN) matches if FUN applied to the object returns non-nil.

(guard BOOLEXP) matches if BOOLEXP evaluates to non-nil.

(let UPAT

__EXP__) matches if

__EXP__matches UPAT.

(app FUN UPAT) matches if FUN applied to the object matches UPAT.

If a SYMBOL is used twice in the same pattern (i.e. the pattern is

"non-linear"), then the second occurrence is turned into an `eq'uality test.

QPatterns 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.

,UPAT matches if the UPattern UPAT matches.

STRING matches if the object is `equal' to STRING.

ATOM matches if the object is `eq' to ATOM.

FUN can take the form

SYMBOL or (lambda ARGS BODY) in which case it's called with one argument.

(F ARG1 .. ARGn) in which case F gets called with an n+1'th argument

which is the value being matched.

So a FUN of the form SYMBOL is equivalent to one of the form (FUN).

FUN can refer to variables bound earlier in the pattern.

FUN is assumed to be pure, i.e. it can be dropped if its result is not used,

and two identical calls can be merged into one.

E.g. you can match pairs where the cdr is larger than the car with a pattern

like `(,a . ,(pred (< a))) or, with more checks:

`(,(and a (pred numberp)) . ,(and (pred numberp) (pred (< a))))