0

Does pcase allow performing expressions when all conditions in pcase fail?

For instance, consider

 (pcase csel  
    ("bracemk" (expression-a))
    ("expression" (expression-b)))

Want to cater for the condition where csel does not match "bracemk" or "expression".

Dilna
  • 1,173
  • 3
  • 10
  • 1
    You can add a third `_` pattern after the other two that matches anything else. See [`(info "(elisp) pcase Macro")`](https://www.gnu.org/software/emacs/manual/html_node/elisp/pcase-Macro.html). – Basil Jun 21 '22 at 18:42
  • 1
    `C-h f` is your friend. *Ask Emacs* (first). – Drew Jun 21 '22 at 18:44

1 Answers1

1

Um, let's have a look at the docs (C-h f pcase). Second para reads

Each PATTERN expands, in essence, to a predicate to call on EXPVAL. When the return value of that call is non-nil, PATTERN matches. PATTERN can take one of the forms:

_ matches anything.

Punchline:

(pcase csel  
    ("bracemk" (expression-a))
    ("expression" (expression-b))
    (_ (clean-up)))

should do the trick.

Fran Burstall
  • 3,665
  • 10
  • 18