Well, that's my fourth commit for this patch.
The reason is cky emphasized that the "real lisper" never use square
bracket. Anyway, I confess
square bracket is just my own style. So I think must make this patch
according to all Guilers' taste  if I want this patch to be helpful.
Four times for one patch. oh GOD...

On Thu, Dec 29, 2011 at 6:20 PM, Nala Ginrut <nalagin...@gmail.com> wrote:

> Hmm... think I've deleted all the things for debug.
>
> On Thu, Dec 29, 2011 at 5:46 PM, Nala Ginrut <nalagin...@gmail.com> wrote:
>
>> Sorry, there's a typo.
>> Here it is.
>>
>>
>> On Thu, Dec 29, 2011 at 5:32 PM, Nala Ginrut <nalagin...@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?
>>>
>>>
>>
>
From 39155a1ddebd4da0cd13a4bcae93395f39765c0e Mon Sep 17 00:00:00 2001
From: NalaGinrut <nalagin...@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 via email to