From: ludo@gnu.org (Ludovic Courtès)
To: guile-user@gnu.org
Subject: Re: regex-case
Date: Mon, 08 Feb 2016 15:29:39 +0100 [thread overview]
Message-ID: <87oabrgtrg.fsf@gnu.org> (raw)
In-Reply-To: 61E420AD-70B6-4DEA-A7DD-EB123E22EFD0@verizon.net
Matt Wette <matthew.wette@verizon.net> 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’.
next prev parent reply other threads:[~2016-02-08 14:29 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-06 19:13 regex-case Matt Wette
2016-02-06 19:23 ` regex-case Matt Wette
2016-02-06 19:49 ` regex-case Marko Rauhamaa
2016-02-06 22:42 ` regex-case Matt Wette
2016-02-07 8:15 ` regex-case Marko Rauhamaa
2016-02-06 22:10 ` regex-case Matt Wette
2016-02-08 14:29 ` Ludovic Courtès [this message]
2016-02-11 1:19 ` regex-case Matt Wette
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87oabrgtrg.fsf@gnu.org \
--to=ludo@gnu.org \
--cc=guile-user@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).