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

Re: Match-result submatch extraction is weird

This page is part of the web mail archives of SRFI 115 from before July 7th, 2015. The new archives for SRFI 115 contain all messages, not just those from before July 7th, 2015.



On Wed, Oct 16, 2013 at 4:23 AM, Peter Bex <Peter.Bex@xxxxxxxxx> wrote:
Hi all,

After clearing the initial roadblocks, I tried to use the library.
Being used to irregex I naively typed away and got this:

(define m (regexp-match '(seq ($ "x") "y") "xy"))
(rx-match-submatch m 1) => ERROR!

So, I looked up the syntax again and was confused:  why does the
rx-match-submatch procedure require the input string again?

Actually I can't remember why I made this change.

The advantage is that it uses one word less memory
for each match (and while running for each active
state in the search).  It's also nicer on GC if you have
a long-lived match object but don't actually need to
extract any substrings (unlikely).

On the other hand it's less convenient, and can give
weird results if passed the wrong string as you point
out.  It's also a bad design if you want a chunked
string API like in IrRegex.

Unless anyone has any other objections, I'll change the
rx-match-submatch API to omit the string input.

-- 
Alex