clarification for regexp-replace in srfi-115 / chibi.regex

Skip to first unread message

Duy Nguyen

Apr 9, 2020, 5:03:48 AM4/9/20
to, Arthur A. Gleckler
This was posted in srfi-115 list, but I hope to catch Alex's attention
by doing it here instead.

'subst' parameter of regexp-replace is described like this

subst can be a string, an integer or symbol indicating the contents of
a numbered or named submatch of re, 'pre for the substring to the left
of the match, or 'post for the substring to the right of the match.

This makes replacement very limited. I found that chibi.regex accepts
'subst' as a _list_ of those items too. With that we can start doing
something like this regexp

s/\(<first>\)...\(<second>\)/blah \2 - \1/'

The SRFI should probably mention that it is an error if a capture
group is named 'pre or 'post because it's ambiguous. Each Scheme
implementation can decide whatever they want to do in that case.

Also, 'subst' can be a procedure in chibi.regex and that makes
replacement much more flexible.

Is it reasonable to amend the SRFI like above? As far as I know, all
srfi-115 implementations out there are based on chibi.regex, which
already supports that. The only exception is Gauche, which translates
SRE to its own AST syntax, and I made sure that it supports the same.

If the SRFI is set in stone, I think we could make a new one and let
it be voted to replace srfi-115 in r7rs-large.

Alex Shinn

Apr 9, 2020, 9:45:50 AM4/9/20
to, Arthur A. Gleckler
Thanks for the ping, I'll follow up on the SRFI list.


You received this message because you are subscribed to the Google Groups "chibi-scheme" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit
Reply all
Reply to author
0 new messages