From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Leo Liu Newsgroups: gmane.emacs.bugs Subject: bug#19814: 24.4; pcase-lambda Date: Sun, 08 Feb 2015 17:01:00 +0800 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1423386133 31213 80.91.229.3 (8 Feb 2015 09:02:13 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 8 Feb 2015 09:02:13 +0000 (UTC) To: 19814@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Feb 08 10:02:13 2015 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YKNkq-0005aC-7k for geb-bug-gnu-emacs@m.gmane.org; Sun, 08 Feb 2015 10:02:12 +0100 Original-Received: from localhost ([::1]:55867 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YKNkp-0001fD-EX for geb-bug-gnu-emacs@m.gmane.org; Sun, 08 Feb 2015 04:02:11 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44384) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YKNkl-0001eG-9o for bug-gnu-emacs@gnu.org; Sun, 08 Feb 2015 04:02:08 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YKNkg-0002fO-FI for bug-gnu-emacs@gnu.org; Sun, 08 Feb 2015 04:02:07 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:45917) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YKNkg-0002fC-D2 for bug-gnu-emacs@gnu.org; Sun, 08 Feb 2015 04:02:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1YKNkg-0006pL-4G; Sun, 08 Feb 2015 04:02:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Leo Liu Original-Sender: "Debbugs-submit" Resent-CC: monnier@iro.umontreal.ca, bug-gnu-emacs@gnu.org Resent-Date: Sun, 08 Feb 2015 09:02:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 19814 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org X-Debbugs-Original-Xcc: Stefan Monnier Original-Received: via spool by submit@debbugs.gnu.org id=B.142338609326203 (code B ref -1); Sun, 08 Feb 2015 09:02:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 8 Feb 2015 09:01:33 +0000 Original-Received: from localhost ([127.0.0.1]:37156 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YKNkC-0006oY-Ef for submit@debbugs.gnu.org; Sun, 08 Feb 2015 04:01:32 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:42404) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YKNk9-0006oG-Nd for submit@debbugs.gnu.org; Sun, 08 Feb 2015 04:01:30 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YKNjz-0002PK-Mi for submit@debbugs.gnu.org; Sun, 08 Feb 2015 04:01:24 -0500 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:55567) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YKNjz-0002PG-Kl for submit@debbugs.gnu.org; Sun, 08 Feb 2015 04:01:19 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44068) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YKNju-0001dj-SI for bug-gnu-emacs@gnu.org; Sun, 08 Feb 2015 04:01:19 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YKNjq-0002Ms-7H for bug-gnu-emacs@gnu.org; Sun, 08 Feb 2015 04:01:14 -0500 Original-Received: from mail-pd0-f178.google.com ([209.85.192.178]:36673) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YKNjq-0002Mc-2X for bug-gnu-emacs@gnu.org; Sun, 08 Feb 2015 04:01:10 -0500 Original-Received: by pdjp10 with SMTP id p10so14327913pdj.3 for ; Sun, 08 Feb 2015 01:01:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:mime-version:content-type; bh=p4S6arXmQseHQen67cTZ/qghYIqW/r9c5i1LFCsC4SM=; b=C5L4gAWlvGpa5LMiy+RSBEysC7R89R06mewfWApFFrdnbZOXNe8aMQb29JwrXvoj3R u0J7BzuSkTpOaKumdAgkhtuGZtMtuGGkSFIS6LuBa9xHaaaEkrdmizi99h10F3oMNA4X sr82XGB/EN3mmo9j05QlsGiDYgfiXPTzy3SivM/4rbEznM/134woGEm5jMoo/nFaFVeN Lh0hg5lfYCCV9ecyWUm2GlqSabn1a3IOmLrg6z5EOUAW6jU/cSIH1joeDlBbFwNpG2uq SLfTvwxE+gyzN7YupWAzJSPhLWm1ZXoDtW8Z9UPDGAMdeMh/DDxNF1kLAfQbWp6YRVQ2 Cp+w== X-Received: by 10.70.88.9 with SMTP id bc9mr19240196pdb.145.1423386069141; Sun, 08 Feb 2015 01:01:09 -0800 (PST) Original-Received: from Shidais-iMac.local ([128.199.230.246]) by mx.google.com with ESMTPSA id uq7sm12919582pbc.48.2015.02.08.01.01.05 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 08 Feb 2015 01:01:08 -0800 (PST) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:99161 Archived-At: --=-=-= Content-Type: text/plain The attached patch intends to implement pcase-lambda with lambda-list being a list of positional UPatterns. &rest is supported. Comments? --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=pcase-lambda.diff Content-Description: pcase-lambda.diff 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)) --=-=-=--