unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Nala Ginrut <nalaginrut@gmail.com>
To: guile-devel <guile-devel@gnu.org>
Subject: Re: [PATCH] add regexp-split
Date: Thu, 29 Dec 2011 18:20:49 +0800	[thread overview]
Message-ID: <CAPjoZocvsHVD=sXJ3zoRpVHQnGS1sksLhYFbr2iqeaUi3q09VA@mail.gmail.com> (raw)
In-Reply-To: <CAPjoZofnZUKwxR2pVuGEaMPP1Gdht_yHA52nUcX57RsuC0RTUw@mail.gmail.com>


[-- Attachment #1.1: Type: text/plain, Size: 842 bytes --]

Hmm... think I've deleted all the things for debug.

On Thu, Dec 29, 2011 at 5:46 PM, Nala Ginrut <nalaginrut@gmail.com> wrote:

> Sorry, there's a typo.
> Here it is.
>
>
> On Thu, Dec 29, 2011 at 5:32 PM, Nala Ginrut <nalaginrut@gmail.com> wrote:
>
>> 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.
>>
>> ------python code-----
>> >>> import re
>> >>> re.split("([^0-9])", "123+456*/")
>> [’123’, ’+’, ’456’, ’*’, ’’, ’/’, ’’]
>> --------code end-------
>>
>> The Guile version:
>>
>> ----------guile code-------
>> (regexp-split "([^0-9])"  "123+456*/")
>> ==>("123" "+" "456" "*" "" "/" "")
>> ----------code end--------
>>
>> Anyone interested in it?
>>
>>
>

[-- Attachment #1.2: Type: text/html, Size: 1679 bytes --]

[-- Attachment #2: 0001-ADD-regexp-split.patch --]
[-- Type: text/x-patch, Size: 1440 bytes --]

From 39155a1ddebd4da0cd13a4bcae93395f39765c0e Mon Sep 17 00:00:00 2001
From: NalaGinrut <NalaGinrut@gmail.com>
Date: Thu, 29 Dec 2011 18:19:00 +0800
Subject: [PATCH] ADD regexp-split

---
 module/ice-9/regex.scm |   20 +++++++++++++++++++-
 1 files changed, 19 insertions(+), 1 deletions(-)

diff --git a/module/ice-9/regex.scm b/module/ice-9/regex.scm
index f7b94b7..2877419 100644
--- a/module/ice-9/regex.scm
+++ b/module/ice-9/regex.scm
@@ -41,7 +41,7 @@
   #:export (match:count match:string match:prefix match:suffix
            regexp-match? regexp-quote match:start match:end match:substring
            string-match regexp-substitute fold-matches list-matches
-           regexp-substitute/global))
+           regexp-substitute/global regexp-split))
 
 ;; References:
 ;;
@@ -226,3 +226,21 @@
                         (begin
                           (do-item (car items)) ; This is not.
                           (next-item (cdr items)))))))))))
+                          
+(define regexp-split
+  (lambda (regex str)
+    (let ([ret (fold-matches 
+		regex str (list '() 0 '(""))
+		(lambda (m prev)
+		  (let* ([ll (car prev)]
+			 [start (cadr prev)]
+			 [tail (match:suffix m)]
+			 [end (match:start m)]
+			 [s (string-copy str start end)]
+			 )
+		    (list `(,@ll ,s ,(match:substring m)) 
+			  (match:end m) tail)
+		    )))])
+      `(,@(car ret) ,(caddr ret))
+      )))
+                          
-- 
1.7.0.4


  reply	other threads:[~2011-12-29 10:20 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-29  9:32 [PATCH] add regexp-split Nala Ginrut
2011-12-29  9:46 ` Nala Ginrut
2011-12-29 10:20   ` Nala Ginrut [this message]
2011-12-29 13:58     ` Nala Ginrut
2011-12-30  5:34       ` Daniel Hartwig
2011-12-30  8:46         ` Nala Ginrut
2011-12-30  9:05           ` Nala Ginrut
     [not found]           ` <CAN3veRdFQyOthFTSLE7v9x3_A4HTPX99DSmDx26dBkeyy=MTDQ@mail.gmail.com>
2011-12-30  9:42             ` Daniel Hartwig
2011-12-30 11:40               ` Nala Ginrut
2011-12-30 11:47                 ` Nala Ginrut
2011-12-30 15:23                   ` Daniel Hartwig
2011-12-30 10:14 ` Marijn
2011-12-30 10:56   ` Nala Ginrut
2011-12-30 11:48     ` Marijn
2011-12-30 11:52       ` Nala Ginrut
2011-12-30 13:23         ` Marijn
2011-12-30 14:57           ` Daniel Hartwig
2011-12-31  1:46             ` Daniel Hartwig
2011-12-31  2:32               ` Eli Barzilay
2011-12-31  3:16                 ` Daniel Hartwig
2011-12-31  3:21                   ` Eli Barzilay
2011-12-31  4:37                     ` Daniel Hartwig
2011-12-31  7:00                       ` Eli Barzilay
2011-12-30 13:03 ` Neil Jerram
2011-12-30 15:12   ` Nala Ginrut
2011-12-30 16:26     ` Neil Jerram
2011-12-30 16:46       ` Nala Ginrut
2012-01-07 22:44     ` Andy Wingo
2011-12-30 15:33   ` Daniel Hartwig
2011-12-30 15:58     ` Nala Ginrut
  -- strict thread matches above, loose matches on Subject: below --
2013-02-01  9:24 Nala Ginrut

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAPjoZocvsHVD=sXJ3zoRpVHQnGS1sksLhYFbr2iqeaUi3q09VA@mail.gmail.com' \
    --to=nalaginrut@gmail.com \
    --cc=guile-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).