From: Marko Rauhamaa <marko@pacujo.net>
To: Matt Wette <matthew.wette@verizon.net>
Cc: guile-user@gnu.org
Subject: Re: regex-case
Date: Sat, 06 Feb 2016 21:49:02 +0200 [thread overview]
Message-ID: <87a8ndsjpt.fsf@elektro.pacujo.net> (raw)
In-Reply-To: <61E420AD-70B6-4DEA-A7DD-EB123E22EFD0@verizon.net> (Matt Wette's message of "Sat, 06 Feb 2016 11:13:25 -0800")
Matt Wette <matthew.wette@verizon.net>:
> Comments on syntax appreciated. — Matt
>
> === test ================
> (define str "foo")
>
> (regex-case str
> (("^([a-z]+)\\(([0-9]+)\\)$" v i)
> (list v i))
> (("^([a-z]+)$" v)
> (list v "1”)))
> =>
> (“foo” “1”)
>
>
> === syntax ==============
> (regex-case <string>
> ((<pattern> <var> <var> …) <body>)
> ((<pattern> <var> <var> …) <body>)
> (else <body>)
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<name>...)
(<URL: https://docs.python.org/3/library/re.html?highlight=regex#reg
ular-expression-syntax>)
[2] Seamless constant string concatenation as in C:
#define PREFIX "..."
#define MIDDLE "..."
#define SUFFIX "..."
...
{
int status = 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
next prev parent reply other threads:[~2016-02-06 19:49 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 ` Marko Rauhamaa [this message]
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 ` regex-case Ludovic Courtès
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=87a8ndsjpt.fsf@elektro.pacujo.net \
--to=marko@pacujo.net \
--cc=guile-user@gnu.org \
--cc=matthew.wette@verizon.net \
/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).