From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Marko Rauhamaa Newsgroups: gmane.lisp.guile.user Subject: Re: regex-case Date: Sat, 06 Feb 2016 21:49:02 +0200 Message-ID: <87a8ndsjpt.fsf@elektro.pacujo.net> References: <61E420AD-70B6-4DEA-A7DD-EB123E22EFD0@verizon.net> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1454788161 26699 80.91.229.3 (6 Feb 2016 19:49:21 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 6 Feb 2016 19:49:21 +0000 (UTC) Cc: guile-user@gnu.org To: Matt Wette Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sat Feb 06 20:49:21 2016 Return-path: Envelope-to: guile-user@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 1aS8r9-0002q6-Ro for guile-user@m.gmane.org; Sat, 06 Feb 2016 20:49:19 +0100 Original-Received: from localhost ([::1]:56420 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aS8r9-00042k-Be for guile-user@m.gmane.org; Sat, 06 Feb 2016 14:49:19 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60522) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aS8qw-0003w9-UH for guile-user@gnu.org; Sat, 06 Feb 2016 14:49:08 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aS8qv-0002uE-TE for guile-user@gnu.org; Sat, 06 Feb 2016 14:49:06 -0500 Original-Received: from [2001:1bc8:1a0:5384:7a2b:cbff:fe9f:e508] (port=57185 helo=pacujo.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aS8qv-0002tE-MC for guile-user@gnu.org; Sat, 06 Feb 2016 14:49:05 -0500 Original-Received: from elektro.pacujo.net (192.168.1.200) by elektro.pacujo.net; Sat, 6 Feb 2016 21:49:02 +0200 Original-Received: by elektro.pacujo.net (sSMTP sendmail emulation); Sat, 06 Feb 2016 21:49:02 +0200 In-Reply-To: <61E420AD-70B6-4DEA-A7DD-EB123E22EFD0@verizon.net> (Matt Wette's message of "Sat, 06 Feb 2016 11:13:25 -0800") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:1bc8:1a0:5384:7a2b:cbff:fe9f:e508 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:12370 Archived-At: Matt Wette : > Comments on syntax appreciated. =E2=80=94 Matt > > =3D=3D=3D test =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > (define str "foo") > > (regex-case str > (("^([a-z]+)\\(([0-9]+)\\)$" v i) > (list v i)) > (("^([a-z]+)$" v) > (list v "1=E2=80=9D))) > =3D> > (=E2=80=9Cfoo=E2=80=9D =E2=80=9C1=E2=80=9D) > > > =3D=3D=3D syntax =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > (regex-case =20 > (( =E2=80=A6) ) > (( =E2=80=A6) ) > (else ) Seems like a great idea, especially since the compilation of the regular expression can be done at compile-time. Only two additions would be needed to make it better: [1] Python's named substrings: (?P...) () [2] Seamless constant string concatenation as in C: #define PREFIX "..." #define MIDDLE "..." #define SUFFIX "..." ... { int status =3D regcomp(®, PREFIX MIDDLE SUFFIX, 0); } Now, I understand [1] is not in your hands, but named substrings are essential in the understandability and maintainability of regular expression code. You might be able to do something about [2]. Without that capacity, regular expressions might turn into kilometer-long lines or annoying (string-concatenate) calls. > I was thinking the above expansion has some chance (if it lives in the > regex module?) to memoize the make-regexp part during optimization. That would be crucial, I'm thinking. Marko