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 17:46:54 +0800	[thread overview]
Message-ID: <CAPjoZofnZUKwxR2pVuGEaMPP1Gdht_yHA52nUcX57RsuC0RTUw@mail.gmail.com> (raw)
In-Reply-To: <CAPjoZocdjvUhSyNVpSECtpQE57TvLLdzMCMYXvd-4xuA4=WuNw@mail.gmail.com>


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

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: 1249 bytes --]

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

From 7ecd9cfbb97b436ed9417f4962bc04264bcdb5e4 Mon Sep 17 00:00:00 2001
From: NalaGinrut <NalaGinrut@gmail.com>
Date: Thu, 29 Dec 2011 17:45:43 +0800
Subject: [PATCH] ADD regexp-split

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

diff --git a/module/ice-9/regex.scm b/module/ice-9/regex.scm
index f7b94b7..2ab28de 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,23 @@
                         (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 0 '(""))
+		 (lambda (m prev)
+		   (let* ([ll (car prev)]
+			  [count (1+ (cadr prev))]
+			  [start (caddr prev)]
+			  [tail (match:suffix m)]
+			  [end (match:start m)]
+			  [s (string-copy str start end)]
+			  )
+		     (list `(,@ll ,s ,(match:substring m)) 
+			   count (match:end m) tail)
+		     )))] ;; end fold-matches
+	   ) ;; end let*
+      `(,@(car ret) ,(cadddr ret))
+      )))
+                                
-- 
1.7.0.4


  reply	other threads:[~2011-12-29  9:46 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 [this message]
2011-12-29 10:20   ` Nala Ginrut
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=CAPjoZofnZUKwxR2pVuGEaMPP1Gdht_yHA52nUcX57RsuC0RTUw@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).