GNU bug report logs - #19814
24.4; pcase-lambda

Previous Next

Package: emacs;

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

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Leo Liu <sdl.web <at> gmail.com>
Cc: tracker <at> debbugs.gnu.org
Subject: bug#19814: closed (24.4; pcase-lambda)
Date: Mon, 09 Feb 2015 02:18:02 +0000
[Message part 1 (text/plain, inline)]
Your message dated Mon, 09 Feb 2015 10:17:40 +0800
with message-id <m2iofbg75n.fsf <at> gmail.com>
and subject line Re: bug#19814: 24.4; pcase-lambda
has caused the debbugs.gnu.org bug report #19814,
regarding 24.4; pcase-lambda
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs <at> 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)]
From: Leo Liu <sdl.web <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.4; pcase-lambda
Date: Sun, 08 Feb 2015 17:01:00 +0800
[Message part 3 (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))
[Message part 5 (message/rfc822, inline)]
From: Leo Liu <sdl.web <at> gmail.com>
To: 19814-done <at> debbugs.gnu.org
Subject: Re: bug#19814: 24.4; pcase-lambda
Date: Mon, 09 Feb 2015 10:17:40 +0800
Version: 25.1


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.