diff options
author | Stefan Monnier <monnier@iro.umontreal.ca> | 2021-08-12 11:04:30 -0400 |
---|---|---|
committer | Stefan Monnier <monnier@iro.umontreal.ca> | 2021-08-12 11:04:30 -0400 |
commit | 96d83a854673797952e678796e2165c187a24f54 (patch) | |
tree | dc1ab81b1c0f6acda9add3cde33491596399309a | |
parent | 0a611a5d7fa4e1186f98a2f98da2d000a87c8b9b (diff) | |
download | emacs-96d83a854673797952e678796e2165c187a24f54.tar.gz emacs-96d83a854673797952e678796e2165c187a24f54.tar.bz2 emacs-96d83a854673797952e678796e2165c187a24f54.zip |
* lisp/emacs-lisp/pcase.el (pcase-setq): Align its semantics with `pcase-let`
* test/lisp/emacs-lisp/pcase-tests.el (pcase-tests-setq): Rename from
pcase-setq and ajust accordingly.
-rw-r--r-- | lisp/emacs-lisp/pcase.el | 18 | ||||
-rw-r--r-- | test/lisp/emacs-lisp/pcase-tests.el | 15 |
2 files changed, 17 insertions, 16 deletions
diff --git a/lisp/emacs-lisp/pcase.el b/lisp/emacs-lisp/pcase.el index d111d9e41f8..63b187be02b 100644 --- a/lisp/emacs-lisp/pcase.el +++ b/lisp/emacs-lisp/pcase.el @@ -326,7 +326,8 @@ Evaluation happens sequentially as in `setq' (not in parallel). An example: (pcase-setq `((,a) [(,b)]) '((1) [(2)])) -When a PATTERN doesn't match it's VALUE, the pair is silently skipped. +VAL is presumed to match PAT. Failure to match may signal an error or go +undetected, binding variables to arbitrary values, such as nil. \(fn PATTERNS VALUE PATTERN VALUES ...)" (declare (debug (&rest [pcase-PAT form]))) @@ -348,13 +349,14 @@ When a PATTERN doesn't match it's VALUE, the pair is silently skipped. (t (pcase-compile-patterns val - (list (cons pat - (lambda (varvals &rest _) - `(setq ,@(mapcan (lambda (varval) - (let ((var (car varval)) - (val (cadr varval))) - (list var val))) - varvals))))))))) + `((,pat + . ,(lambda (varvals &rest _) + `(setq ,@(mapcan (lambda (varval) + (let ((var (car varval)) + (val (cadr varval))) + (list var val))) + varvals)))) + (pcase--dontcare . ignore)))))) (defun pcase--trivial-upat-p (upat) (and (symbolp upat) (not (memq upat pcase--dontcare-upats)))) diff --git a/test/lisp/emacs-lisp/pcase-tests.el b/test/lisp/emacs-lisp/pcase-tests.el index 67882d00d86..7ad01e7aef7 100644 --- a/test/lisp/emacs-lisp/pcase-tests.el +++ b/test/lisp/emacs-lisp/pcase-tests.el @@ -110,21 +110,16 @@ (should-error (pcase 1 ((cl-type notatype) 'integer)))) -(ert-deftest pcase-setq () - (should (equal (let (a b) - (pcase-setq `(,a ,b) nil) - (list a b)) - (list nil nil))) - +(ert-deftest pcase-tests-setq () (should (equal (let (a b) (pcase-setq `((,a) (,b)) '((1) (2))) (list a b)) (list 1 2))) - (should (equal (list 'unset 'unset) + (should (equal (list nil nil) (let ((a 'unset) (b 'unset)) - (pcase-setq `(,a ,b) nil) + (pcase-setq `(head ,a ,b) nil) (list a b)))) (should (equal (let (a b) @@ -132,6 +127,10 @@ (list a b)) '(1 2))) + (should-error (let (a b) + (pcase-setq `[,a ,b] nil) + (list a b))) + (should (equal (let (a b) (pcase-setq a 1 b 2) (list a b)) |