From debbugs-submit-bounces@debbugs.gnu.org Mon Aug 25 04:03:11 2014 Received: (at submit) by debbugs.gnu.org; 25 Aug 2014 08:03:11 +0000 Received: from localhost ([127.0.0.1]:51336 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XLpF8-0004cj-No for submit@debbugs.gnu.org; Mon, 25 Aug 2014 04:03:11 -0400 Received: from eggs.gnu.org ([208.118.235.92]:55917) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XLpF5-0004cU-8A for submit@debbugs.gnu.org; Mon, 25 Aug 2014 04:03:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XLpEq-0006yV-S6 for submit@debbugs.gnu.org; Mon, 25 Aug 2014 04:03:01 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,FREEMAIL_FROM, T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:52201) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XLpEq-0006yR-PK for submit@debbugs.gnu.org; Mon, 25 Aug 2014 04:02:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57587) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XLpEh-0003EC-Ka for bug-gnu-emacs@gnu.org; Mon, 25 Aug 2014 04:02:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XLpEY-0006vE-J4 for bug-gnu-emacs@gnu.org; Mon, 25 Aug 2014 04:02:43 -0400 Received: from mail-pa0-x22f.google.com ([2607:f8b0:400e:c03::22f]:51199) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XLpEY-0006ul-BJ for bug-gnu-emacs@gnu.org; Mon, 25 Aug 2014 04:02:34 -0400 Received: by mail-pa0-f47.google.com with SMTP id kx10so20393281pab.6 for ; Mon, 25 Aug 2014 01:02:32 -0700 (PDT) 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=ewteWI1ek1f2bBhpcp6lHHivA0o7SAglltUg1Lv3Y+A=; b=sZk4DXEeNYVmQvTRZf6BpzOMGqgnkH7YgsuIyx051T2rkben3GZcZyvPCRYMsJWzT0 jTztDREo1mkw+H/wBqOwtbHtmhTusxkKqpTTkxTpewIob0950qJbbRc/5zpC8bHX/1To yeEJawrbWOCx3fusf1syq/cQg6emuNJ8bonA0QZuCYdPGh7Vz8C4z4sCGpiXoWQda/Q/ gWheTGcCI4nd/6Dzg8WZeviOvdLFiaRuL18o4CIST39nwawpdocpTU7jOpctpzPar6h9 KW1I91csk5/k38h0LfSeBJsInMJCF4PQff17GncySz42aeEJzjg+mw+BxiR6WPsVMwNM qI0A== X-Received: by 10.69.18.11 with SMTP id gi11mr2282121pbd.163.1408953752724; Mon, 25 Aug 2014 01:02:32 -0700 (PDT) Received: from fortuna ([221.222.148.29]) by mx.google.com with ESMTPSA id dp6sm56179211pdb.51.2014.08.25.01.02.30 for (version=TLSv1.1 cipher=RC4-SHA bits=128/128); Mon, 25 Aug 2014 01:02:31 -0700 (PDT) From: Leo Liu To: bug-gnu-emacs@gnu.org Subject: 24.4.50; [PATCH] vector QPattern for pcase X-Debbugs-CC: Stefan Monnier Date: Mon, 25 Aug 2014 16:02:26 +0800 Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.0 (----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.0 (----) --=-=-= Content-Type: text/plain Hi Stefan, The attached patch (inspired by your byte-code-function qpattern patch) seems to add vector QPattern to pcase. Could you review it and give me any comments? Thanks. I haven't wanted vector qpattern badly enough until just now having put up with many many: (and (pred vectorp) io (let `(io_request ,from ,replyas ,request) (cl-coerce io 'list))) which is both ugly and inefficient. Thanks, Leo --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=pcase-vector-qpat.diff Content-Description: pcase-vector-qpat.diff === modified file 'lisp/emacs-lisp/pcase.el' --- lisp/emacs-lisp/pcase.el 2014-01-03 04:40:30 +0000 +++ lisp/emacs-lisp/pcase.el 2014-08-25 07:52:34 +0000 @@ -54,6 +54,7 @@ ;;; Code: (require 'macroexp) +(eval-when-compile (require 'cl-lib)) ;; Macro-expansion of pcase is reasonably fast, so it's not a problem ;; when byte-compiling a file, but when interpreting the code, if the pcase @@ -447,6 +448,22 @@ (pcase--mutually-exclusive-p #'consp (cadr pat))) '(:pcase--fail . nil)))) +(defun pcase--split-vector (len syms pat) + (cond + ;; A QPattern for a vector of same length + ((and (eq (car-safe pat) '\`) + (vectorp (cadr pat)) + (= len (length (cadr pat)))) + (let ((qpat (cadr pat))) + (cons `(and ,@(cl-loop for s in syms for i from 0 + collect `(match ,s . ,(pcase--upat (aref qpat i))))) + :pcase--fail))) + ;; Other QPatterns go to the `else' side. + ((eq (car-safe pat) '\`) '(:pcase--fail . nil)) + ((and (eq (car-safe pat) 'pred) + (pcase--mutually-exclusive-p #'vectorp (cadr pat))) + '(:pcase--fail . nil)))) + (defun pcase--split-equal (elem pat) (cond ;; The same match will give the same result. @@ -738,8 +755,27 @@ ((eq (car-safe qpat) '\,) (error "Can't use `,UPATTERN")) ((floatp qpat) (error "Floating point patterns not supported")) ((vectorp qpat) - ;; FIXME. - (error "Vector QPatterns not implemented yet")) + (let* ((len (length qpat)) + (syms (mapcar (lambda (i) (make-symbol (format "xaref%s" i))) + (number-sequence 0 (1- len)))) + (splitrest (pcase--split-rest + sym + (lambda (pat) (pcase--split-vector len syms pat)) + rest)) + (then-rest (car splitrest)) + (else-rest (cdr splitrest)) + (then-body (pcase--u1 + `(,@(cl-loop for s in syms for i from 0 + collect `(match ,s . ,(pcase--upat (aref qpat i)))) + ,@matches) + code vars then-rest))) + (pcase--if + `(and (vectorp ,sym) (= (length ,sym) ,len)) + (macroexp-let* + (cl-loop for s in syms for i from 0 + when (get s 'pcase-used) collect `(,s (aref ,sym ,i))) + then-body) + (pcase--u else-rest)))) ((consp qpat) (let* ((syma (make-symbol "xcar")) (symd (make-symbol "xcdr")) --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Thu Aug 28 22:42:48 2014 Received: (at 18327) by debbugs.gnu.org; 29 Aug 2014 02:42:48 +0000 Received: from localhost ([127.0.0.1]:52989 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XNC9H-0000MV-LY for submit@debbugs.gnu.org; Thu, 28 Aug 2014 22:42:47 -0400 Received: from mail-pa0-f51.google.com ([209.85.220.51]:54953) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XNC9D-0000MB-Mj for 18327@debbugs.gnu.org; Thu, 28 Aug 2014 22:42:44 -0400 Received: by mail-pa0-f51.google.com with SMTP id rd3so5125930pab.38 for <18327@debbugs.gnu.org>; Thu, 28 Aug 2014 19:42:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:references:face:date:in-reply-to:message-id :user-agent:mime-version:content-type; bh=HmLzBSJJ2J60LVhmEQ+/7LQY8sJ6rj+Z4rkxLSboZxY=; b=ZkZWJkUZa2TDZSWYro+M0mDAlkTLdPvfdEIy+NezKOSLz0jpjd4ovfPUnWSq1PmGyr tYk+8yC2MErASF8/szRYtSPBFwDbNePSb1r1QWCmjVpffaWPzBdnqbNhDzxxKGNrF9+U aX2oGG6cIpCxy4u31wgzYlWNtF5lcKSY4Hc0tNWQUcQdCGZQFmm68yBZ4GDtYLLUTbgO P/w52jFL4MgaUXDpwcdwrIsN79oZRPxOdIyV6U62gr1G/ThMk5t2uTU+UP3WshYuRKCd Do4odYNQBfGzNH0tc5UP38sb+2ThD1LDIYOCzYLfzsLOnMZNrvLYPH7zFuCkKHPMt64B taew== X-Received: by 10.68.186.33 with SMTP id fh1mr11487946pbc.105.1409280157431; Thu, 28 Aug 2014 19:42:37 -0700 (PDT) Received: from fortuna ([221.222.148.29]) by mx.google.com with ESMTPSA id m1sm7807535pdh.18.2014.08.28.19.42.36 for <18327@debbugs.gnu.org> (version=TLSv1.1 cipher=RC4-SHA bits=128/128); Thu, 28 Aug 2014 19:42:36 -0700 (PDT) From: Leo Liu To: 18327@debbugs.gnu.org Subject: Re: bug#18327: 24.4.50; [PATCH] vector QPattern for pcase References: Face: iVBORw0KGgoAAAANSUhEUgAAACgAAAAoBAMAAAB+0KVeAAAAGFBMVEUzRVhbQj4eZqO6SjnT eWpxnMetm5b6/PmidmqrAAAAAWJLR0QAiAUdSAAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1F B9cBBwMLBfKABCMAAAFoSURBVCjPtZI9a8MwEIaFoc7aYDdelQMna0Em3tsSr0XUeE2Q6a22a+v+ fk8fSSBkbDUI6dHpfe9OEvRgiD+ApqKPJgJeB6iUUXWESjUe/ig38AJrhqqvaU2nTIXbNvOQ40fe qdry4kyGoVWsfCQalXpHnJGM01wjWdYbMlXNFdsZDO69m9aqNqxEJqTEgbM5OF7wlEfIoll1Ked4 LbM5X2EdILLokEdmI8z7g5cKED0cuTC930TYhy7ZDekkXVGw/L60TguJePPxcJF48lpsSUWEA/Ju jGFNgJOXc4Hz7TmAdBeu5Ve4AEjOi2/2jfd3cAJZ+IbNrvdjgBZY01b+HTuG3cLws6BJZqVOj/pp T0OqVwx3rFq+QmJwx3loK5JSLEhDIt62+mtC2C+SrAUxEbV6C6v2BRbd6pILBKFpepKZJHgGgrKF sptSUUoczpwg2pQ7ZH1tgs0ou/917mzz6Cs2//C978cv5l07L02orIEAAAAASUVORK5CYII= Date: Fri, 29 Aug 2014 10:42:33 +0800 In-Reply-To: (Leo Liu's message of "Mon, 25 Aug 2014 16:02:26 +0800") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4.50 (CentOS 6.5) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 18327 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) On 2014-08-25 16:02 +0800, Leo Liu wrote: > The attached patch (inspired by your byte-code-function qpattern patch) > seems to add vector QPattern to pcase. Could you review it and give me > any comments? Thanks. Any comments on this patch? I have a package that is waiting to depend on vector QPattern headily ;) Thanks, Leo. From debbugs-submit-bounces@debbugs.gnu.org Thu Sep 04 12:22:06 2014 Received: (at 18327) by debbugs.gnu.org; 4 Sep 2014 16:22:06 +0000 Received: from localhost ([127.0.0.1]:58961 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XPZnS-0005QT-3Q for submit@debbugs.gnu.org; Thu, 04 Sep 2014 12:22:06 -0400 Received: from relais.videotron.ca ([24.201.245.36]:47626) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XPZnQ-0005Py-C4 for 18327@debbugs.gnu.org; Thu, 04 Sep 2014 12:22:04 -0400 MIME-version: 1.0 Content-transfer-encoding: 7BIT Content-type: text/plain; CHARSET=US-ASCII Received: from ceviche.home ([24.201.170.218]) by VL-VM-MR005.ip.videotron.ca (Oracle Communications Messaging Exchange Server 7u4-22.01 64bit (built Apr 21 2011)) with ESMTP id <0NBD0080PXGN7S30@VL-VM-MR005.ip.videotron.ca> for 18327@debbugs.gnu.org; Thu, 04 Sep 2014 12:21:59 -0400 (EDT) Received: by ceviche.home (Postfix, from userid 20848) id A3D3D660C4; Thu, 04 Sep 2014 12:21:59 -0400 (EDT) From: Stefan Monnier To: Leo Liu Subject: Re: bug#18327: 24.4.50; [PATCH] vector QPattern for pcase Message-id: References: Date: Thu, 04 Sep 2014 12:21:59 -0400 In-reply-to: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4.50 (gnu/linux) X-Spam-Score: 1.0 (+) X-Debbugs-Envelope-To: 18327 Cc: 18327@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.0 (+) > The attached patch (inspired by your byte-code-function qpattern patch) > seems to add vector QPattern to pcase. Could you review it and give me > any comments? Thanks. Please double-check that it doesn't break bootstrap (CL uses pcase as well, and I have some vague recollection of bumping into problems in this area, which is why pcase doesn't use CL). Also the patch needs to update pcase's docstring (based on my understanding of your code, you only handle qpatterns of the form [QPAT1..QPATn], right?). Stefan From debbugs-submit-bounces@debbugs.gnu.org Thu Sep 04 13:31:40 2014 Received: (at 18327) by debbugs.gnu.org; 4 Sep 2014 17:31:40 +0000 Received: from localhost ([127.0.0.1]:58986 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XPasm-0007BP-6Z for submit@debbugs.gnu.org; Thu, 04 Sep 2014 13:31:40 -0400 Received: from mail-pd0-f176.google.com ([209.85.192.176]:49942) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XPasg-0007B9-VT for 18327@debbugs.gnu.org; Thu, 04 Sep 2014 13:31:38 -0400 Received: by mail-pd0-f176.google.com with SMTP id w10so4621203pde.7 for <18327@debbugs.gnu.org>; Thu, 04 Sep 2014 10:31:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:references:face:date:in-reply-to:message-id :user-agent:mime-version:content-type; bh=o+X+jqsmLS+TA0bq0DpDzTYXgt56Shg8XEs66/VSk+Y=; b=1B0IyIsnKtsDx+ZW1kkvNVW0TdtB4WJyzzEiv6P7PTwldn092bipRLYn3osqRqJ3Ul qvDnRA50Fp5GH08f4bUVzTvASF3WByi1OeZMndQIVr0LcuL++cTBDl89rRnpCZQU7+B1 xy3516K6ZVAgYBRsdoIyEXA5RgVFSxaiw7413K7LAflBBoyXf7akrpQverkQb3zUWz0H /kaRj6h6UkpCbB6av0IdBfzcJJzVfXFUlnjr+XVSSv4TAB2BXtTCYZ2oXiNuYAXgMf+H CkCYxF0ND8I6FYfdtxwzv0lk0b5k+hfKxIzgKCj925KSwYlY0Kv1lv1sAJQOSTRKT0zH 1EWQ== X-Received: by 10.66.245.34 with SMTP id xl2mr10974813pac.90.1409851884613; Thu, 04 Sep 2014 10:31:24 -0700 (PDT) Received: from fortuna ([221.222.152.125]) by mx.google.com with ESMTPSA id ny7sm2226180pab.38.2014.09.04.10.31.22 for (version=TLSv1.1 cipher=RC4-SHA bits=128/128); Thu, 04 Sep 2014 10:31:23 -0700 (PDT) From: Leo Liu To: Stefan Monnier Subject: Re: bug#18327: 24.4.50; [PATCH] vector QPattern for pcase References: Face: iVBORw0KGgoAAAANSUhEUgAAACgAAAAoBAMAAAB+0KVeAAAAGFBMVEUzRVhbQj4eZqO6SjnT eWpxnMetm5b6/PmidmqrAAAAAWJLR0QAiAUdSAAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1F B9cBBwMLBfKABCMAAAFoSURBVCjPtZI9a8MwEIaFoc7aYDdelQMna0Em3tsSr0XUeE2Q6a22a+v+ fk8fSSBkbDUI6dHpfe9OEvRgiD+ApqKPJgJeB6iUUXWESjUe/ig38AJrhqqvaU2nTIXbNvOQ40fe qdry4kyGoVWsfCQalXpHnJGM01wjWdYbMlXNFdsZDO69m9aqNqxEJqTEgbM5OF7wlEfIoll1Ked4 LbM5X2EdILLokEdmI8z7g5cKED0cuTC930TYhy7ZDekkXVGw/L60TguJePPxcJF48lpsSUWEA/Ju jGFNgJOXc4Hz7TmAdBeu5Ve4AEjOi2/2jfd3cAJZ+IbNrvdjgBZY01b+HTuG3cLws6BJZqVOj/pp T0OqVwx3rFq+QmJwx3loK5JSLEhDIt62+mtC2C+SrAUxEbV6C6v2BRbd6pILBKFpepKZJHgGgrKF sptSUUoczpwg2pQ7ZH1tgs0ou/917mzz6Cs2//C978cv5l07L02orIEAAAAASUVORK5CYII= Date: Fri, 05 Sep 2014 01:31:18 +0800 In-Reply-To: (Stefan Monnier's message of "Thu, 04 Sep 2014 12:21:59 -0400") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4.50 (CentOS 6.5) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 18327 Cc: 18327@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) --=-=-= Content-Type: text/plain On 2014-09-04 12:21 -0400, Stefan Monnier wrote: > Please double-check that it doesn't break bootstrap (CL uses pcase as > well, and I have some vague recollection of bumping into problems in > this area, which is why pcase doesn't use CL). Indeed, that failed to bootstrap. I get rid of cl-loop. > Also the patch needs to update pcase's docstring (based on my > understanding of your code, you only handle qpatterns of the form > [QPAT1..QPATn], right?). Yes, it only handles fixed-size vector qpatterns. Having built this simpler one your byte-code qpattern patch makes a lot more sense to me. And the `...' notation looks cool. For the packages I am writing fixed-size qpattern is more than enough ;) > Stefan Thanks, Leo --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=pcase-vector-qpat2.diff Content-Description: pcase-vector-qpat2.diff === modified file 'lisp/emacs-lisp/pcase.el' --- lisp/emacs-lisp/pcase.el 2014-01-03 04:40:30 +0000 +++ lisp/emacs-lisp/pcase.el 2014-09-04 17:16:34 +0000 @@ -108,11 +108,11 @@ \"non-linear\"), then the second occurrence is turned into an `eq'uality test. QPatterns can take the following forms: - (QPAT1 . QPAT2) matches if QPAT1 matches the car and QPAT2 the cdr. - ,UPAT matches if the UPattern UPAT matches. - STRING matches if the object is `equal' to STRING. - ATOM matches if the object is `eq' to ATOM. -QPatterns for vectors are not implemented yet. + (QPAT1 . QPAT2) matches if QPAT1 matches the car and QPAT2 the cdr. + [QPAT1 QPAT2] matches if QPAT1/2 match the first/second elements + ,UPAT matches if the UPattern UPAT matches. + STRING matches if the object is `equal' to STRING. + ATOM matches if the object is `eq' to ATOM. PRED can take the form FUNCTION in which case it gets called with one argument. @@ -447,6 +447,24 @@ (pcase--mutually-exclusive-p #'consp (cadr pat))) '(:pcase--fail . nil)))) +(defun pcase--split-vector (syms pat) + (cond + ;; A QPattern for a vector of same length + ((and (eq (car-safe pat) '\`) + (vectorp (cadr pat)) + (= (length syms) (length (cadr pat)))) + (let ((qpat (cadr pat))) + (cons `(and ,@(mapcar (lambda (s) + `(match ,(car s) . + ,(pcase--upat (aref qpat (cdr s))))) + syms)) + :pcase--fail))) + ;; Other QPatterns go to the `else' side. + ((eq (car-safe pat) '\`) '(:pcase--fail . nil)) + ((and (eq (car-safe pat) 'pred) + (pcase--mutually-exclusive-p #'vectorp (cadr pat))) + '(:pcase--fail . nil)))) + (defun pcase--split-equal (elem pat) (cond ;; The same match will give the same result. @@ -738,8 +756,30 @@ ((eq (car-safe qpat) '\,) (error "Can't use `,UPATTERN")) ((floatp qpat) (error "Floating point patterns not supported")) ((vectorp qpat) - ;; FIXME. - (error "Vector QPatterns not implemented yet")) + (let* ((len (length qpat)) + (syms (mapcar (lambda (i) (cons (make-symbol (format "xaref%s" i)) i)) + (number-sequence 0 (1- len)))) + (splitrest (pcase--split-rest + sym + (lambda (pat) (pcase--split-vector syms pat)) + rest)) + (then-rest (car splitrest)) + (else-rest (cdr splitrest)) + (then-body (pcase--u1 + `(,@(mapcar (lambda (s) + `(match ,(car s) . + ,(pcase--upat (aref qpat (cdr s))))) + syms) + ,@matches) + code vars then-rest))) + (pcase--if + `(and (vectorp ,sym) (= (length ,sym) ,len)) + (macroexp-let* (delq nil (mapcar (lambda (s) + (and (get (car s) 'pcase-used) + `(,(car s) (aref ,sym ,(cdr s))))) + syms)) + then-body) + (pcase--u else-rest)))) ((consp qpat) (let* ((syma (make-symbol "xcar")) (symd (make-symbol "xcdr")) --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Thu Sep 04 16:35:05 2014 Received: (at 18327) by debbugs.gnu.org; 4 Sep 2014 20:35:06 +0000 Received: from localhost ([127.0.0.1]:59064 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XPdkH-0003KV-Cn for submit@debbugs.gnu.org; Thu, 04 Sep 2014 16:35:05 -0400 Received: from relais.videotron.ca ([24.201.245.36]:46956) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XPdkE-0003Jx-Pb for 18327@debbugs.gnu.org; Thu, 04 Sep 2014 16:35:03 -0400 MIME-version: 1.0 Content-transfer-encoding: 7BIT Content-type: text/plain; CHARSET=US-ASCII Received: from ceviche.home ([24.201.170.218]) by VL-VM-MR005.ip.videotron.ca (Oracle Communications Messaging Exchange Server 7u4-22.01 64bit (built Apr 21 2011)) with ESMTP id <0NBE0093R9690C90@VL-VM-MR005.ip.videotron.ca> for 18327@debbugs.gnu.org; Thu, 04 Sep 2014 16:34:57 -0400 (EDT) Received: by ceviche.home (Postfix, from userid 20848) id 2766E660C4; Thu, 04 Sep 2014 16:34:58 -0400 (EDT) From: Stefan Monnier To: Leo Liu Subject: Re: bug#18327: 24.4.50; [PATCH] vector QPattern for pcase Message-id: References: Date: Thu, 04 Sep 2014 16:34:58 -0400 In-reply-to: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4.50 (gnu/linux) X-Spam-Score: 1.0 (+) X-Debbugs-Envelope-To: 18327 Cc: 18327@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.0 (+) >> Also the patch needs to update pcase's docstring (based on my >> understanding of your code, you only handle qpatterns of the form >> [QPAT1..QPATn], right?). > Yes, it only handles fixed-size vector qpatterns. Good, thanks. > + [QPAT1 QPAT2] matches if QPAT1/2 match the first/second elements This makes it sound you only handle vectors of size 2. > +(defun pcase--split-vector (syms pat) > + (cond > + ;; A QPattern for a vector of same length Please punctuate your comments. > @@ -738,8 +756,30 @@ > ((eq (car-safe qpat) '\,) (error "Can't use `,UPATTERN")) > ((floatp qpat) (error "Floating point patterns not supported")) > ((vectorp qpat) > - ;; FIXME. > - (error "Vector QPatterns not implemented yet")) > + (let* ((len (length qpat)) > + (syms (mapcar (lambda (i) (cons (make-symbol (format "xaref%s" i)) i)) > + (number-sequence 0 (1- len)))) > + (splitrest (pcase--split-rest > + sym > + (lambda (pat) (pcase--split-vector syms pat)) > + rest)) > + (then-rest (car splitrest)) > + (else-rest (cdr splitrest)) > + (then-body (pcase--u1 > + `(,@(mapcar (lambda (s) > + `(match ,(car s) . > + ,(pcase--upat (aref qpat (cdr s))))) > + syms) > + ,@matches) > + code vars then-rest))) > + (pcase--if > + `(and (vectorp ,sym) (= (length ,sym) ,len)) > + (macroexp-let* (delq nil (mapcar (lambda (s) > + (and (get (car s) 'pcase-used) > + `(,(car s) (aref ,sym ,(cdr s))))) > + syms)) > + then-body) > + (pcase--u else-rest)))) If that can be split into its own function without too much trouble, then please do so. Other than that, it looks OK, feel free to install (but do add a NEWS entry as well). Stefan From debbugs-submit-bounces@debbugs.gnu.org Thu Sep 04 21:31:53 2014 Received: (at 18327) by debbugs.gnu.org; 5 Sep 2014 01:31:53 +0000 Received: from localhost ([127.0.0.1]:59189 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XPiNU-0002Bx-T7 for submit@debbugs.gnu.org; Thu, 04 Sep 2014 21:31:53 -0400 Received: from mail-pd0-f180.google.com ([209.85.192.180]:41664) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XPiNS-0002Bj-94 for 18327@debbugs.gnu.org; Thu, 04 Sep 2014 21:31:50 -0400 Received: by mail-pd0-f180.google.com with SMTP id p10so14836042pdj.11 for <18327@debbugs.gnu.org>; Thu, 04 Sep 2014 18:31:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:references:face:date:in-reply-to:message-id :user-agent:mime-version:content-type; bh=T0ZrapaRzCRuPoRFK/NKI5k44/F9PY8VTQ+ylbp0hz0=; b=Chwm2fKmlBu4Ao+0Q3t6i547L5I/iP9WEpXbCOisL8ULyecxWMHeMYPyYrpadivzyv sFwiin0BJ4QTG95lamtb0t2uQRaukpZaB7x4fJxhWvAOgDliKw0pe+euChsId2Ba1SGk 46PDkXGbXZnykOykWy+B2M1bNiTwegNVlRHeJgp8LAZF81JAKKbTxgUC2XIWT4jEIkMs y/wZyAlzk4rCDIxaJdqKiUxyMQ0hR0NoNQmOmZXCini/fovcNGreJcngkGkkkHtNQ8yw oXzZWfGO4UeyeksC6+qrbVixuY6UVxbAzIwRjd4rXlTazh3NFpM4QAocqDAm40x+JXvI 7KMQ== X-Received: by 10.70.131.40 with SMTP id oj8mr15080887pdb.47.1409880703648; Thu, 04 Sep 2014 18:31:43 -0700 (PDT) Received: from fortuna ([221.222.152.125]) by mx.google.com with ESMTPSA id ta6sm181115pac.14.2014.09.04.18.31.41 for (version=TLSv1.1 cipher=RC4-SHA bits=128/128); Thu, 04 Sep 2014 18:31:42 -0700 (PDT) From: Leo Liu To: Stefan Monnier Subject: Re: bug#18327: 24.4.50; [PATCH] vector QPattern for pcase References: Face: iVBORw0KGgoAAAANSUhEUgAAACgAAAAoBAMAAAB+0KVeAAAAMFBMVEUaFRZLMy1dTENxVzKQ WiCrXQ97cmO/dSqSh3akjGTApXy5sJ7Sxo/Sz8Xo6eP9//xJbkruAAAAAWJLR0QAiAUdSAAAAAlw SFlzAAACxQAAAsUBidZ/7wAAAAd0SU1FB9cBBwMJOwHXewoAAAIBSURBVCjPVdNBiNNAFADQ6J4F x3hThHZBBC+WCFI8SS0iezRDcMHLHkLAg6gJH/fgYQ9xYlj2sLK4KHgqCgXFhda2Idmr4kkQPZQ0 nkQMbTypbMmMM2m7ZgYSmMef/5OZPwo7HFnx3uKPcmj0Dht1LWZJ+Hvr7dIFZXRUwl9VRTuuKDJ+ U44gjscknK4hhJaCkYRsWjmBtLqXlJAG2wipNe18OZJu1BBq1E8xafl4s6Jq2mUZGftU1y7CCxnp FVUDWJXx4C66BKBnErbuoaYNtoRTu6EZBsCbMn7W+5qOAR6WvxNOby9jHWC9hAf3n304CdiAByXs 3Nh9roLDkyb/sWV712vYwaLSAn8CPMHIAAzOPDKP2COAFm4Y4ODVWc6xG7KXsN7UeUJjjimx2uwd gCgNhr0i8C/xyCD5CiCKAMY3Bf5oDzx//w/fimscdcAZU2jv9sedx6+nYPPFIoWI/GK6QZ+EFGOR ErAjCnV3vPZ7XqlTIMbOLY7fLcvvmT7rXNWaGDexIY44N12TG2PDp7vqyl57dnCeuWwyNpnEURxk fTbDYeBnKRn4oejPYI4sH6WviBumEZ/GxX4X/x6EcURFZ7E071bjQGAxpcOAEOJuTiroDEea5Szv rVWLYfl7ZiQwSUToxrkux7OLixAWGz22+HIyWTRYcVfomOwvzusfjtVIGgLHf3MAAAAASUVORK5C YII= Date: Fri, 05 Sep 2014 09:31:37 +0800 In-Reply-To: (Stefan Monnier's message of "Thu, 04 Sep 2014 16:34:58 -0400") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4.50 (CentOS 6.5) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 18327 Cc: 18327@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) On 2014-09-04 16:34 -0400, Stefan Monnier wrote: > If that can be split into its own function without too much trouble, ^ | +--- should be possible if I know what is `that'? Thanks for the comments, BTW. - Leo From debbugs-submit-bounces@debbugs.gnu.org Tue Feb 23 07:15:59 2016 Received: (at 18327) by debbugs.gnu.org; 23 Feb 2016 12:15:59 +0000 Received: from localhost ([127.0.0.1]:39405 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aYBsl-00084X-Fn for submit@debbugs.gnu.org; Tue, 23 Feb 2016 07:15:59 -0500 Received: from hermes.netfonds.no ([80.91.224.195]:44191) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aYBsk-00084O-9C for 18327@debbugs.gnu.org; Tue, 23 Feb 2016 07:15:58 -0500 Received: from cpe-60-225-211-161.nsw.bigpond.net.au ([60.225.211.161] helo=mouse) by hermes.netfonds.no with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1aYBsJ-0006Oo-6z; Tue, 23 Feb 2016 13:15:31 +0100 From: Lars Ingebrigtsen To: Stefan Monnier Subject: Re: bug#18327: 24.4.50; [PATCH] vector QPattern for pcase References: Date: Tue, 23 Feb 2016 23:15:26 +1100 In-Reply-To: (Stefan Monnier's message of "Thu, 04 Sep 2014 16:34:58 -0400") Message-ID: <87twkzoc69.fsf@gnus.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-MailScanner-ID: 1aYBsJ-0006Oo-6z X-Netfonds-MailScanner: Found to be clean X-Netfonds-MailScanner-From: larsi@gnus.org MailScanner-NULL-Check: 1456834532.11871@QVU6xunp+GyA2LB4xujM4g X-Spam-Status: No X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 18327 Cc: 18327@debbugs.gnu.org, Leo Liu X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) Stefan Monnier writes: >> + [QPAT1 QPAT2] matches if QPAT1/2 match the first/second elements It seems like pcase now has support for vectors, so I'm closing this bug report. -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no From debbugs-submit-bounces@debbugs.gnu.org Tue Feb 23 07:16:09 2016 Received: (at control) by debbugs.gnu.org; 23 Feb 2016 12:16:09 +0000 Received: from localhost ([127.0.0.1]:39409 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aYBsv-00085W-M9 for submit@debbugs.gnu.org; Tue, 23 Feb 2016 07:16:09 -0500 Received: from hermes.netfonds.no ([80.91.224.195]:44197) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aYBsu-00085O-4d for control@debbugs.gnu.org; Tue, 23 Feb 2016 07:16:08 -0500 Received: from cpe-60-225-211-161.nsw.bigpond.net.au ([60.225.211.161] helo=mouse) by hermes.netfonds.no with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1aYBsS-0006Oz-76 for control@debbugs.gnu.org; Tue, 23 Feb 2016 13:15:40 +0100 Date: Tue, 23 Feb 2016 23:15:35 +1100 Message-Id: <87si0joc60.fsf@gnus.org> To: control@debbugs.gnu.org From: Lars Ingebrigtsen Subject: control message for bug #18327 X-MailScanner-ID: 1aYBsS-0006Oz-76 X-Netfonds-MailScanner: Found to be clean X-Netfonds-MailScanner-From: larsi@gnus.org MailScanner-NULL-Check: 1456834542.65155@dktE7DOHQdugFcCOoVejhQ X-Spam-Status: No X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) tags 18327 fixed close 18327 From unknown Mon Jun 16 23:43:51 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Wed, 23 Mar 2016 11:24:04 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator