guile-devel
[Top][All Lists]
Advanced

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

Re: [PATCH] add regexp-split


From: Andy Wingo
Subject: Re: [PATCH] add regexp-split
Date: Sat, 07 Jan 2012 23:44:16 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux)

On Fri 30 Dec 2011 16:12, Nala Ginrut <address@hidden> writes:

> So the previous discussion didn't make this proc put into Guile?
> Now that so many people interested in this topic. 

I think it would make a nice addition to (ice-9 regexp).  I don't think
we need to capture the delimiters though; some other function can do
that.

What do you think about this:

  (define* (regexp-split regex str #:optional (flags 0))
    (let ((ret (fold-matches
                regex str (cons '() 0)
                (lambda (m prev)
                  (let ((parts (car prev))
                        (start (cdr prev)))
                    (cons (cons (substring str start (match:start m))
                                parts)
                          (match:end m))))
                flags)))
      (reverse (cons (substring str (cdr ret)) (car ret)))))

Andy
-- 
http://wingolog.org/



reply via email to

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