Match-result submatch extraction is weird Peter Bex (15 Oct 2013 19:25 UTC)
Re: Match-result submatch extraction is weird Alex Shinn (15 Oct 2013 23:04 UTC)

Match-result submatch extraction is weird Peter Bex 15 Oct 2013 19:23 UTC

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?

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

That means I can do something completely bogus like the following, too!
(rx-match-submatch m "abc" 1) => "a"

This makes no sense, and I didn't see any rationale for this design.
It's also a step back from irregex, where the input string is kept
around in the match result object, and where you can simply extract it:

(define m (regexp-match '(seq ($ "x") "y") "xy"))
(irregex-match-substring m 1) => "x"

Cheers,
Peter
--
http://www.more-magic.net