From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Newsgroups: gmane.lisp.guile.user Subject: Re: regex-case Date: Mon, 08 Feb 2016 15:29:39 +0100 Message-ID: <87oabrgtrg.fsf@gnu.org> 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: 8bit X-Trace: ger.gmane.org 1454941827 3600 80.91.229.3 (8 Feb 2016 14:30:27 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 8 Feb 2016 14:30:27 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Mon Feb 08 15:30:19 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 1aSmpU-0006tl-Uv for guile-user@m.gmane.org; Mon, 08 Feb 2016 15:30:17 +0100 Original-Received: from localhost ([::1]:45291 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSmpP-0002Fs-EZ for guile-user@m.gmane.org; Mon, 08 Feb 2016 09:30:11 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56953) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSmpG-0002FZ-2S for guile-user@gnu.org; Mon, 08 Feb 2016 09:30:02 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aSmpA-0000Q7-Nf for guile-user@gnu.org; Mon, 08 Feb 2016 09:30:00 -0500 Original-Received: from plane.gmane.org ([80.91.229.3]:39435) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSmpA-0000Px-Gt for guile-user@gnu.org; Mon, 08 Feb 2016 09:29:56 -0500 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1aSmp8-0006ZW-Kh for guile-user@gnu.org; Mon, 08 Feb 2016 15:29:54 +0100 Original-Received: from pluto.bordeaux.inria.fr ([193.50.110.57]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 08 Feb 2016 15:29:54 +0100 Original-Received: from ludo by pluto.bordeaux.inria.fr with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 08 Feb 2016 15:29:54 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 28 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: pluto.bordeaux.inria.fr X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 20 =?utf-8?Q?Pluvi=C3=B4se?= an 224 de la =?utf-8?Q?R=C3=A9volution?= X-PGP-Key-ID: 0x3D9AEBB5 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5 X-OS: x86_64-unknown-linux-gnu User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) Cancel-Lock: sha1:SbEBTsyU7AcYSFbUvGuLQEPd4W8= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 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:12376 Archived-At: Matt Wette skribis: > (regex-case str > (("^([a-z]+)\\(([0-9]+)\\)$" v i) > (list v i)) > (("^([a-z]+)$" v) > (list v "1”))) Sounds useful and convenient! > (let ((t-292 (make-regexp "^([a-z]+)\\(([0-9]+)\\)$")) > (t-293 (make-regexp "^([a-z]+)$"))) > (cond ((regexp-exec t-292 str) > => > (lambda (m) > (let ((v (match:substring m 1)) > (i (match:substring m 2))) > (list v i)))) > ((regexp-exec t-293 str) > => > (lambda (m) > (let ((v (match:substring m 1))) (list v "1")))))) When the ‘else’ clause is missing, I think it would be best to throw an error like ‘match’ does—it’s rarely helpful to return #unspecified in those cases. Ludo’.