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.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 19814 in the body.
You can then email your comments to 19814 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to monnier <at> iro.umontreal.ca, bug-gnu-emacs <at> gnu.org:
bug#19814; Package emacs. (Sun, 08 Feb 2015 09:02:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Leo Liu <sdl.web <at> gmail.com>:
New bug report received and forwarded. Copy sent to monnier <at> iro.umontreal.ca, bug-gnu-emacs <at> gnu.org. (Sun, 08 Feb 2015 09:02:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

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 1 (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))

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19814; Package emacs. (Sun, 08 Feb 2015 19:19:02 GMT) Full text and rfc822 format available.

Message #8 received at 19814 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Leo Liu <sdl.web <at> gmail.com>
Cc: 19814 <at> debbugs.gnu.org
Subject: Re: bug#19814: 24.4; pcase-lambda
Date: Sun, 08 Feb 2015 14:18:00 -0500
> +(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))

Maybe it'd be better to just splitting the body into 2 parts:
- "declarations", which would include docstrings, `declare's, and interactive
- code.


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19814; Package emacs. (Mon, 09 Feb 2015 01:15:02 GMT) Full text and rfc822 format available.

Message #11 received at 19814 <at> debbugs.gnu.org (full text, mbox):

From: Leo Liu <sdl.web <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 19814 <at> debbugs.gnu.org
Subject: Re: bug#19814: 24.4; pcase-lambda
Date: Mon, 09 Feb 2015 09:14:30 +0800
On 2015-02-09 03:18 +0800, Stefan Monnier wrote:
> Maybe it'd be better to just splitting the body into 2 parts:
> - "declarations", which would include docstrings, `declare's, and interactive
> - code.

Coincidentally I have done just that locally :)

(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))

Leo




Reply sent to Leo Liu <sdl.web <at> gmail.com>:
You have taken responsibility. (Mon, 09 Feb 2015 02:18:01 GMT) Full text and rfc822 format available.

Notification sent to Leo Liu <sdl.web <at> gmail.com>:
bug acknowledged by developer. (Mon, 09 Feb 2015 02:18:02 GMT) Full text and rfc822 format available.

Message #16 received at 19814-done <at> debbugs.gnu.org (full text, mbox):

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




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19814; Package emacs. (Mon, 09 Feb 2015 04:28:02 GMT) Full text and rfc822 format available.

Message #19 received at 19814 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Leo Liu <sdl.web <at> gmail.com>
Cc: 19814 <at> debbugs.gnu.org
Subject: Re: bug#19814: 24.4; pcase-lambda
Date: Sun, 08 Feb 2015 23:27:49 -0500
>> Maybe it'd be better to just splitting the body into 2 parts:
>> - "declarations", which would include docstrings, `declare's, and interactive
>> - code.
> Coincidentally I have done just that locally :)

> (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))

No, I meant (DECLS . BODY) such that

  (let ((x (macroexp-parse-body body)))
    (append (car x) (cdr x)))

return something `equal' to `body'.




        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19814; Package emacs. (Mon, 09 Feb 2015 05:32:02 GMT) Full text and rfc822 format available.

Message #22 received at 19814 <at> debbugs.gnu.org (full text, mbox):

From: Leo Liu <sdl.web <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 19814 <at> debbugs.gnu.org
Subject: Re: bug#19814: 24.4; pcase-lambda
Date: Mon, 09 Feb 2015 13:30:58 +0800
On 2015-02-09 12:27 +0800, Stefan Monnier wrote:
> No, I meant (DECLS . BODY) such that
>
>   (let ((x (macroexp-parse-body body)))
>     (append (car x) (cdr x)))
>
> return something `equal' to `body'.

Ahh, I see. We can certainly do that.

But isn't the version committed to master slightly more flexible i.e.
one can easily access the individual DOC, DECLARE or INTERACTIVE form?
And if one wants to use the prelude (without the `nil') as a whole it is
just (remq nil (car PARSED-BODY)) away? What do you think?

Leo




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 09 Mar 2015 11:24:03 GMT) Full text and rfc822 format available.

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.