[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: regex-case

From: Marko Rauhamaa
Subject: Re: regex-case
Date: Sat, 06 Feb 2016 21:49:02 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Matt Wette <address@hidden>:

> 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>...)

 [2] Seamless constant string concatenation as in C:

     #define PREFIX "..."
     #define MIDDLE "..."
     #define SUFFIX "..."
         int status = regcomp(&reg, 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.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]