From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Nala Ginrut Newsgroups: gmane.lisp.guile.devel Subject: Re: [PATCH] add regexp-split Date: Fri, 30 Dec 2011 23:58:23 +0800 Message-ID: References: <8762gyjjp2.fsf@neil-laptop.ossau.uklinux.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=bcaec54ee65e79d2e804b5514d7c X-Trace: dough.gmane.org 1325260722 3435 80.91.229.12 (30 Dec 2011 15:58:42 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 30 Dec 2011 15:58:42 +0000 (UTC) Cc: guile-devel To: Daniel Hartwig Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Fri Dec 30 16:58:35 2011 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Rgeqi-00055C-G9 for guile-devel@m.gmane.org; Fri, 30 Dec 2011 16:58:28 +0100 Original-Received: from localhost ([::1]:46313 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rgeqi-0008D8-22 for guile-devel@m.gmane.org; Fri, 30 Dec 2011 10:58:28 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:55230) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rgeqf-0008D0-Qb for guile-devel@gnu.org; Fri, 30 Dec 2011 10:58:26 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Rgeqe-0003A1-ID for guile-devel@gnu.org; Fri, 30 Dec 2011 10:58:25 -0500 Original-Received: from mail-vx0-f169.google.com ([209.85.220.169]:39501) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rgeqe-00039v-6L for guile-devel@gnu.org; Fri, 30 Dec 2011 10:58:24 -0500 Original-Received: by vcge1 with SMTP id e1so11996345vcg.0 for ; Fri, 30 Dec 2011 07:58:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=ZWIfWu5NxJJU38FLQaFAgU+/wHYOcCe9JckJ+XdKI4k=; b=YH0JftqzwNzP97XGIQNNDEpKl9uoiJw2jq1OGlQt4iMh1Kxl/P3Tn/ymXqD5jK7G2P hqSjjqOO/vAmfaRw5s1Yky0ajOs+EiTzZQa5r1FP7009VhJYkJ45vPQRrNsYJtI7eGPL vs+idcQq16Cl9VU35ukR1alWrgaHRxtUVl3i0= Original-Received: by 10.220.147.134 with SMTP id l6mr8648859vcv.49.1325260703650; Fri, 30 Dec 2011 07:58:23 -0800 (PST) Original-Received: by 10.52.183.194 with HTTP; Fri, 30 Dec 2011 07:58:23 -0800 (PST) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.220.169 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:13212 Archived-At: --bcaec54ee65e79d2e804b5514d7c Content-Type: text/plain; charset=UTF-8 Now that we have previous thread on this topic, I think it's no need to format a patch. Maybe this will solve the problem: (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 wrote: > On 30 December 2011 21:03, Neil Jerram wrote: > > Nala Ginrut writes: > > > >> hi guilers! > >> It seems like there's no "regexp-split" procedure in Guile. > >> What we have is "string-split" which accepted Char only. > >> So I wrote one for myself. > > > > We've had this topic before, and it only needs a search for > > "regex-split guile" to find it: > > http://old.nabble.com/regex-split-for-Guile-td31093245.html. > > > > 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' > !). > --bcaec54ee65e79d2e804b5514d7c Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Now that we have previous thread on this topic, I think it's no need to= format a patch.

Maybe this will solve the problem:
=
(define* (regexp-split regex str #:optional (flags 0))
=C2= =A0 (let ((ret (fold-matches=C2=A0
=C2= =A0 =C2=A0 =C2=A0regex str (list '() 0 str)
=C2=A0 =C2=A0 =C2=A0(lambd= a (m prev)
(let* ((ll (car prev))
=C2= =A0 =C2=A0 =C2=A0 (start (cadr prev))
=C2=A0 =C2=A0 =C2=A0 (tail (match:s= uffix m))
=C2=A0 =C2=A0 =C2=A0 (end (match:start m))
=C2= =A0 =C2=A0 =C2=A0 (s (substring/shared str start end))
=C2=A0 =C2=A0 =C2= =A0 (groups (map (lambda (n) (match:substring m n))
= =C2=A0 =C2=A0(iota (1- (match:count m))))))
=C2=A0(list `(,@ll ,s ,@group= s) (match:end m) tail)))
=C2= =A0 =C2=A0 =C2=A0flags)))
=C2=A0 =C2=A0 `(,@(car ret) ,(caddr ret= ))))


On Fri, Dec 30, 201= 1 at 11:33 PM, Daniel Hartwig <mandyke@gmail.com> wrote:
On 3= 0 December 2011 21:03, Neil Jerram <neil@ossau.homelinux.net> wrote:
> Nala Ginrut <nalaginrut@gma= il.com> writes:
>
>> hi guilers!
>> It seems like there's no "regexp-split" procedure in= Guile.
>> What we have is "string-split" which accepted Char only.=
>> So I wrote one for myself.
>
> We've had this topic before, and it only needs a search for
> "regex-split guile" to find it:
> http://old.nabble.com/regex-split-for-Guile-td31093245.= html.
>

Good to see that there is continuing interest in this feature.<= br>
IMO, the implementation here is more elegant and readable for it's use<= br> of `fold-matches'. =C2=A0The first implementation from the thread you mention effectively rolls it's own version of `fold-matches' over t= he
result of `list-matches' (which is implemented using `fold-matches'=
!).

--bcaec54ee65e79d2e804b5514d7c--