guile-devel
[Top][All Lists]
Advanced

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

Re: [PATCH] add regexp-split


From: Nala Ginrut
Subject: Re: [PATCH] add regexp-split
Date: Fri, 30 Dec 2011 19:47:17 +0800

Forget to load (srfi-1 iota) ,again...

On Fri, Dec 30, 2011 at 7:40 PM, Nala Ginrut <address@hidden> wrote:
Great! It's better now.
Here's the brand new patch~


On Fri, Dec 30, 2011 at 5:42 PM, Daniel Hartwig <address@hidden> wrote:
On 30 December 2011 16:46, Nala Ginrut <address@hidden> wrote:
> hi Daniel! Very glad to see your reply.
> 1. I also think the order: (regexp str) is strange. But it's according to
> python version.
> And I think the 'string-match' also put regexp before str. Anyway, that's an
> easy mend.

`regexp string' is also the same order as `list-matches' and
`fold-matches'.  Probably best to keep it that way if this is in the
regex module.


>> I would like to see your version support the Python semantics [1]:
>>
>> > If capturing parentheses are used in pattern, then the text of
>> > all groups in the pattern are also returned as part of the resulting
>> > list.
>> [...]
>> > >>> re.split('\W+', 'Words, words, words.')
>> > ['Words', 'words', 'words', '']
>> > >>> re.split('(\W+)', 'Words, words, words.')
>> > ['Words', ', ', 'words', ', ', 'words', '.', '']
>>
>> >>> re.split('((,)?\W+?)', 'Words, words, words.')
>> ['Words', ', ', ',', 'words', ', ', ',', 'words', '.', None, '']

FYI this can be achieved by changing the inner part to:

   (let* ...
          (s (substring string start end))
          (groups (map (lambda (n) (match:substring m n))
                       (iota (1- (match:count m)) 1))))
     (list `(,@ll ,s ,@groups) (match:end m) tail)))

Note: using srfi-1 iota



Attachment: 0001-ADD-regexp-split.patch
Description: Text Data


reply via email to

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