[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#16567: 24.3.50; pcase should signal an error if no case matches
From: |
Leo Liu |
Subject: |
bug#16567: 24.3.50; pcase should signal an error if no case matches |
Date: |
Fri, 12 Sep 2014 10:35:29 +0800 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.4.50 (CentOS 6.5) |
Stefan,
Which name would you prefer, `epcase' or 'pcasex'? Do you see any
problems with the following patch (assume `pcasex' for now)?
Thanks, Leo
=== modified file 'lisp/emacs-lisp/lisp-mode.el'
--- lisp/emacs-lisp/lisp-mode.el 2014-06-19 14:03:45 +0000
+++ lisp/emacs-lisp/lisp-mode.el 2014-09-12 02:28:44 +0000
@@ -197,7 +197,7 @@
(el-vdefs '("defconst" "defcustom" "defvaralias" "defvar-local"
"defface"))
(el-tdefs '("defgroup" "deftheme"))
- (el-kw '("while-no-input" "letrec" "pcase" "pcase-let"
+ (el-kw '("while-no-input" "letrec" "pcase" "pcasex" "pcase-let"
"pcase-let*" "save-restriction" "save-excursion"
"save-selected-window"
;; "eval-after-load" "eval-next-after-load"
=== modified file 'lisp/emacs-lisp/pcase.el'
--- lisp/emacs-lisp/pcase.el 2014-09-06 00:59:00 +0000
+++ lisp/emacs-lisp/pcase.el 2014-09-10 10:44:59 +0000
@@ -68,6 +68,8 @@
(defconst pcase--dontcare-upats '(t _ pcase--dontcare))
+(defvar pcase--dontwarn-upats '(pcase--dontcare))
+
(def-edebug-spec
pcase-UPAT
(&or symbolp
@@ -148,6 +150,15 @@
;; (puthash (car cases) `(,exp ,cases ,@expansion) pcase--memoize-2)
expansion))))
+;;;###autoload
+(defmacro pcasex (exp &rest cases)
+ "The exhausitive version of `pcase' (which see)."
+ (declare (indent 1) (debug pcase))
+ (let* ((x (make-symbol "x"))
+ (pcase--dontwarn-upats (cons x pcase--dontwarn-upats)))
+ (pcase--expand
+ exp (append cases `((,x (error "No clause matching `%S'" ,x)))))))
+
(defun pcase--let* (bindings body)
(cond
((null bindings) (macroexp-progn body))
@@ -280,7 +291,8 @@
vars))))
cases))))
(dolist (case cases)
- (unless (or (memq case used-cases) (eq (car case) 'pcase--dontcare))
+ (unless (or (memq case used-cases)
+ (memq (car case) pcase--dontwarn-upats))
(message "Redundant pcase pattern: %S" (car case))))
(macroexp-let* defs main))))
- bug#16567: 24.3.50; pcase should signal an error if no case matches, (continued)
- bug#16567: 24.3.50; pcase should signal an error if no case matches, Stefan Monnier, 2014/09/10
- bug#16567: 24.3.50; pcase should signal an error if no case matches, Helmut Eller, 2014/09/10
- bug#16567: 24.3.50; pcase should signal an error if no case matches, Stefan Monnier, 2014/09/10
- bug#16567: 24.3.50; pcase should signal an error if no case matches, Leo Liu, 2014/09/10
- bug#16567: 24.3.50; pcase should signal an error if no case matches, Glenn Morris, 2014/09/10
- bug#16567: 24.3.50; pcase should signal an error if no case matches, Stefan Monnier, 2014/09/10
- bug#16567: 24.3.50; pcase should signal an error if no case matches,
Leo Liu <=
- bug#16567: 24.3.50; pcase should signal an error if no case matches, Stefan Monnier, 2014/09/12
- bug#16567: 24.3.50; pcase should signal an error if no case matches, Leo Liu, 2014/09/12
- bug#16567: 24.3.50; pcase should signal an error if no case matches, Stefan Monnier, 2014/09/12
- bug#16567: 24.3.50; pcase should signal an error if no case matches, Leo Liu, 2014/09/13
- bug#16567: 24.3.50; pcase should signal an error if no case matches, Stefan Monnier, 2014/09/13
- bug#16567: 24.3.50; pcase should signal an error if no case matches, Leo Liu, 2014/09/13
- bug#16567: 24.3.50; pcase should signal an error if no case matches, Richard Stallman, 2014/09/10