Questions tagged [pcase]

ML-style pattern-matching macro for Elisp

11 questions
5
votes
2 answers

Match against a variable with pcase

I'm trying to get pcase to match against a let-bound variable. However, I can't seem to get pcase to recognize the variable correctly. See this minimal example: (let ((a 1)) (pcase 2 (a 7))) => 7 ;; as predicted by the docs (let ((a 2)) (pcase…
PythonNut
  • 10,243
  • 2
  • 29
  • 75
3
votes
2 answers

Specify optional matches with pcase

Consider the following form: (pcase '(:def "k" #'foo :wk "ho") (`(:def ,(and (or (pred stringp) (pred vectorp)) key) ,(and (pred xl-sharp-quoted-symbol-p) def) :wk ,(and (pred stringp) desc)) (format "%s | %s | %s" key def…
Aquaactress
  • 1,393
  • 8
  • 11
3
votes
1 answer

pcase matches with rx but not with regex

(rx bos (1+ (in "0-2")) eos) evaluates to "\\`[0-2]+\\'", so I expected these two functions to be equivalent: (defun with-rx (s) (pcase s ((rx bos (1+ (in "0-2")) eos) "matched") (t "not matched"))) (defun with-regex (s) (pcase s …
little-dude
  • 177
  • 6
2
votes
1 answer

Why do rx-let definitions not work inside of pcase?

I am using pattern matching in Emacs Lisp with pcase. I would like to simplify the rx expressions I am using by binding common pattern with rx-let. However, it seems like if you use rx by itself the substitution works as expected. However, if rx is…
2
votes
0 answers

byte-compiling in presence of pcase patterns

TIL that trying to compile anything with pcase matching in it may lead to an explosion of code generated during expansion. Even the most innocent looking patterns may generate hundreds of branches and thousands of lines of code. TBH I would never…
zeRusski
  • 335
  • 1
  • 8
1
vote
1 answer

Using pcase to recursively parse nested lists

So I'm trying to process the following nested list... (setq *test* '("mt" "trello" ("b" "board" ("l" org-trello-show-board-labels) ("d" org-trello-sync-buffer-down) ("u" org-trello-sync-buffer-up) ("s" "setup" ("c"…
Tariq Kamal
  • 390
  • 1
  • 9
1
vote
1 answer

Define negating pcase patterns

I am interested in extending pcase with patterns which: Complement an existing pattern, e.g. (not (pred string-empty-p)). Such a pattern would match where the non-negated form does not match and vice versa. Match when a predicate applied to the…
Basil
  • 12,019
  • 43
  • 69
0
votes
0 answers

Having pcase conditions do nothing

Is it possible to make some of the pcase conditions do nothing? How can I do this if possible?
Dilna
  • 1,173
  • 3
  • 10
0
votes
1 answer

Adding alternative for a face or face name

I am using this function interactively, where the string from completing-read is passed to intern to convert it into a symbol suitable for describe-face. Currently, I want to handle the non-interactive case, where a face is passed directly to the…
Dilna
  • 1,173
  • 3
  • 10
0
votes
1 answer

Matching for unmatched input with pcase

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"…
Dilna
  • 1,173
  • 3
  • 10
0
votes
2 answers

pcase pred not acting right

I've got this (defun testor (s) (if (or (< s 1) (> s 21)) (message "Bad") (message "good"))) which works. But a similar (defun test2 (n) (pcase n ((pred (< n 1)) (message "bad")) ((pred (> n 21)) (message "bad")) (n (message…
147pm
  • 2,907
  • 1
  • 18
  • 39