From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: ludo@gnu.org (Ludovic =?iso-8859-1?Q?Court=E8s?=) Newsgroups: gmane.lisp.guile.devel Subject: Re: =?utf-8?b?4oCYbWF0Y2jigJk=?= and =?utf-8?b?4oCcaw==?= or =?utf-8?b?bW9yZeKAnQ==?= patterns Date: Sun, 19 Sep 2010 23:30:27 +0200 Message-ID: <87wrqhjua4.fsf@gnu.org> References: <877hj0xmcp.fsf@gnu.org> <874oe36pgn.fsf@gnu.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: dough.gmane.org 1284931847 27648 80.91.229.12 (19 Sep 2010 21:30:47 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 19 Sep 2010 21:30:47 +0000 (UTC) Cc: guile-devel@gnu.org To: Alex Shinn Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sun Sep 19 23:30:45 2010 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1OxRTA-0004mW-JG for guile-devel@m.gmane.org; Sun, 19 Sep 2010 23:30:44 +0200 Original-Received: from localhost ([127.0.0.1]:58101 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OxRT9-0004Ya-TU for guile-devel@m.gmane.org; Sun, 19 Sep 2010 17:30:43 -0400 Original-Received: from [140.186.70.92] (port=47652 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OxRT6-0004YV-M2 for guile-devel@gnu.org; Sun, 19 Sep 2010 17:30:41 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OxRT5-0004Op-FY for guile-devel@gnu.org; Sun, 19 Sep 2010 17:30:40 -0400 Original-Received: from mail1-relais-roc.national.inria.fr ([192.134.164.82]:65415) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OxRT5-0004OO-6W for guile-devel@gnu.org; Sun, 19 Sep 2010 17:30:39 -0400 X-IronPort-AV: E=Sophos;i="4.56,389,1280700000"; d="scan'208";a="67840165" Original-Received: from reverse-83.fdn.fr (HELO nixey) ([80.67.176.83]) by mail1-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES128-SHA; 19 Sep 2010 23:30:33 +0200 X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: Jour du Travail de =?iso-8859-1?Q?l'Ann=E9e?= 218 de la =?iso-8859-1?Q?R=E9volution?= X-PGP-Key-ID: 0xEA52ECF4 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 83C4 F8E5 10A3 3B4C 5BEA D15D 77DD 95E2 EA52 ECF4 X-OS: x86_64-unknown-linux-gnu In-Reply-To: (Alex Shinn's message of "Wed, 8 Sep 2010 11:18:18 +0900") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:10941 Archived-At: --=-=-= Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" --==-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi Alex, Alex Shinn writes: > On Mon, Sep 6, 2010 at 9:12 PM, Ludovic Court=C3=A8s wrote: [...] >> I do! =C2=A0:-) >> >> =C2=A0http://git.sv.gnu.org/cgit/guile-rpc.git/tree/modules/rpc/compiler= .scm#n312 >> >> Well it uses only =E2=80=98..1=E2=80=99. =C2=A0The same code would work = with =E2=80=98..1=E2=80=99 replaced >> by =E2=80=98...=E2=80=99, but then errors in the input wouldn=E2=80=99t = be detected as nicely. > > "..1" is actually useful The attached patch adds support for =E2=80=98..1=E2=80=99. I=E2=80=99ll ap= ply it to Guile if you=E2=80=99re OK with applying it upstream. What do you think? BTW, I had fearfully avoided to hack a pattern matcher until now and I was pleased to see how tractable this code is! Thanks, Ludo=E2=80=99. --==-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.12 (GNU/Linux) iEYEARECAAYFAkyWgPcACgkQd92V4upS7PTKHgCdHktj5RkU/Ppz5rh1zSx8W0NK a+wAn2o4tkndtnusxeDVFeB6HXGhR/VV =c7C5 -----END PGP SIGNATURE----- --==-=-=-- --=-=-= Content-Type: text/x-patch Content-Disposition: inline diff --git a/module/ice-9/match.upstream.scm b/module/ice-9/match.upstream.scm index 963b89f..bf3335b 100644 --- a/module/ice-9/match.upstream.scm +++ b/module/ice-9/match.upstream.scm @@ -125,7 +125,7 @@ ;; pattern so far. (define-syntax match-two - (syntax-rules (_ ___ *** quote quasiquote ? $ = and or not set! get!) + (syntax-rules (_ ___ ..1 *** quote quasiquote ? $ = and or not set! get!) ((match-two v () g+s (sk ...) fk i) (if (null? v) (sk ... i) fk)) ((match-two v (quote p) g+s (sk ...) fk i) @@ -161,6 +161,10 @@ (match-extract-vars p (match-gen-search v p q g+s sk fk i) i ())) ((match-two v (p *** . q) g+s sk fk i) (match-syntax-error "invalid use of ***" (p *** . q))) + ((match-two v (p ..1) g+s sk fk i) + (if (pair? v) + (match-one v (p ___) g+s sk fk i) + fk)) ((match-two v (p . q) g+s sk fk i) (if (pair? v) (let ((w (car v)) (x (cdr v))) diff --git a/test-suite/tests/match.test b/test-suite/tests/match.test index 70a15ec..d1432d8 100644 --- a/test-suite/tests/match.test +++ b/test-suite/tests/match.test @@ -67,6 +67,16 @@ ((x . rest) (and (eq? x 'a) (equal? rest '(b c))))))) + (pass-if "list ..1" + (match '(a b c) + ((x ..1) + (equal? x '(a b c))))) + + (pass-if "list ..1, with predicate" + (match '(a b c) + (((and x (? symbol?)) ..1) + (equal? x '(a b c))))) + (pass-if "tree" (let ((tree '(one (two 2) (three 3 (and 4 (and 5)))))) (match tree @@ -79,4 +89,15 @@ (pass-if-exception "tree" exception:match-error (match '(a (b c)) - ((foo (bar)) #t)))) + ((foo (bar)) #t))) + + (pass-if-exception "list ..1" + exception:match-error + (match '() + ((x ..1) #f))) + + (pass-if-exception "list ..1, with predicate" + exception:match-error + (match '(a 0) + (((and x (? symbol?)) ..1) + (equal? x '(a b c)))))) --=-=-=--