GNU bug report logs -
#19814
24.4; pcase-lambda
Previous Next
Reported by: Leo Liu <sdl.web <at> gmail.com>
Date: Sun, 8 Feb 2015 09:02:01 UTC
Severity: normal
Found in version 24.4
Fixed in version 25.1
Done: Leo Liu <sdl.web <at> gmail.com>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
Your bug report
#19814: 24.4; pcase-lambda
which was filed against the emacs package, has been closed.
The explanation is attached below, along with your original report.
If you require more details, please reply to 19814 <at> debbugs.gnu.org.
--
19814: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=19814
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
Version: 25.1
[Message part 3 (message/rfc822, inline)]
[Message part 4 (text/plain, inline)]
The attached patch intends to implement pcase-lambda with lambda-list
being a list of positional UPatterns. &rest is supported. Comments?
[pcase-lambda.diff (text/x-patch, inline)]
diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el
index 868a9578..5d912097 100644
--- a/lisp/emacs-lisp/lisp-mode.el
+++ b/lisp/emacs-lisp/lisp-mode.el
@@ -204,7 +204,7 @@ (pcase-let
"defface"))
(el-tdefs '("defgroup" "deftheme"))
(el-kw '("while-no-input" "letrec" "pcase" "pcase-exhaustive"
- "pcase-let" "pcase-let*" "save-restriction"
+ "pcase-lambda" "pcase-let" "pcase-let*" "save-restriction"
"save-excursion" "save-selected-window"
;; "eval-after-load" "eval-next-after-load"
"save-window-excursion" "save-current-buffer"
diff --git a/lisp/emacs-lisp/macroexp.el b/lisp/emacs-lisp/macroexp.el
index 797de9ab..8fe156c4 100644
--- a/lisp/emacs-lisp/macroexp.el
+++ b/lisp/emacs-lisp/macroexp.el
@@ -297,6 +297,16 @@ (defun macroexpand-all (form &optional environment)
;;; Handy functions to use in macros.
+(defun macroexp-parse-body (exps)
+ "Parse EXPS into (DOC DECLARE-FORM INTERACTIVE-FORM . BODY)."
+ `(,(and (stringp (car exps))
+ (pop exps))
+ ,(and (eq (car-safe (car exps)) 'declare)
+ (pop exps))
+ ,(and (eq (car-safe (car exps)) 'interactive)
+ (pop exps))
+ ,@exps))
+
(defun macroexp-progn (exps)
"Return an expression equivalent to `(progn ,@EXPS)."
(if (cdr exps) `(progn ,@exps) (car exps)))
diff --git a/lisp/emacs-lisp/pcase.el b/lisp/emacs-lisp/pcase.el
index b495793b..0c71451b 100644
--- a/lisp/emacs-lisp/pcase.el
+++ b/lisp/emacs-lisp/pcase.el
@@ -164,6 +164,23 @@ (defmacro pcase-exhaustive (exp &rest cases)
;; FIXME: Could we add the FILE:LINE data in the error message?
exp (append cases `((,x (error "No clause matching `%S'" ,x)))))))
+;;;###autoload
+(defmacro pcase-lambda (lambda-list &rest body)
+ (declare (doc-string 2) (indent defun))
+ (let ((args (make-symbol "args"))
+ (pats (mapcar (lambda (u)
+ (unless (eq u '&rest)
+ (if (eq (car-safe u) '\`) (cadr u) (list '\, u))))
+ lambda-list))
+ (body (macroexp-parse-body body)))
+ ;; Handle &rest
+ (when (eq nil (car (last pats 2)))
+ (setq pats (append (butlast pats 2) (car (last pats)))))
+ `(lambda (&rest ,args)
+ ,@(remq nil (list (nth 0 body) (nth 1 body) (nth 2 body)))
+ (pcase ,args
+ (,(list '\` pats) . ,(nthcdr 3 body))))))
+
(defun pcase--let* (bindings body)
(cond
((null bindings) (macroexp-progn body))
This bug report was last modified 10 years and 110 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.