Here's a revised version, implementing Thien-Thi Nguyen's comments. I
added line breaks for the "cons" and the bottom "if" (I feel that the
top "if" is still simple enough to keep on the same line).
Cheers,
Chris.
* * *
(define (regexp-split-fold match prev)
(if (zero? (match:end match)) prev
(cons* (match:end match)
(substring (match:string match) (car prev) (match:start match))
(cdr prev))))
(define* (regexp-split pat str #:optional (limit 0))
(let* ((result (fold-matches pat str '(0) regexp-split-fold 0
(if (positive? limit) (1- limit) #f)))
(final (cons (substring str (car result))
(cdr result))))
(reverse (if (zero? limit)
(drop-while string-null? final)
final))))