(define* (regexp-split regex str #:optional (flags 0))
(let ((ret (fold-matches
regex str (list '() 0 str)
(lambda (m prev)
(let* ((ll (car prev))
(start (cadr prev))
(tail (match:suffix m))
(end (match:start m))
(s (substring/shared str start end))
(groups (map (lambda (n) (match:substring m n))
(iota (1- (match:count m))))))
(list `(,@ll ,s ,@groups) (match:end m) tail)))
flags)))
`(,@(car ret) ,(caddr ret))))
On Fri, Dec 30, 2011 at 11:33 PM, Daniel Hartwig
<address@hidden> wrote:
Good to see that there is continuing interest in this feature.
IMO, the implementation here is more elegant and readable for it's use
of `fold-matches'. The first implementation from the thread you
mention effectively rolls it's own version of `fold-matches' over the
result of `list-matches' (which is implemented using `fold-matches'
!).