guile-devel
[Top][All Lists]
Advanced

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

Re: regexp-split for Guile


From: Chris K. Jester-Young
Subject: Re: regexp-split for Guile
Date: Tue, 18 Sep 2012 15:59:15 -0400
User-agent: Mutt/1.5.21 (2010-09-15)

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))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]