Re: regexp-split for Guile

2012-10-21 Thread Daniel Hartwig
On 20 October 2012 22:16, Mark H Weaver m...@netris.org wrote: Honestly, this question makes me wonder if the proposed 'regexp-split' is too complicated. If you want to trim whitespace, how about using 'string-trim-right' or 'string-trim-both' before splitting? It seems more likely to do

Re: regexp-split for Guile

2012-10-21 Thread Chris K. Jester-Young
On Sat, Oct 20, 2012 at 10:16:49AM -0400, Mark H Weaver wrote: Sorry, that last example is wrong of course, but both of these examples raise an interesting question about how #:limit and #:trim should interact. To my mind, the top example above is correct. I think the last result should be

Re: regexp-split for Guile

2012-10-21 Thread Chris K. Jester-Young
On Sun, Oct 21, 2012 at 04:20:09PM +0800, Daniel Hartwig wrote: Yes. Keep it simple. Operations like trim-whitespace and drop-empty-strings-from-the-result (mentioned in the previous discussion) are so easy to do outside of regexp-split, why complicate the semantics? So easy, but so

Re: regexp-split for Guile

2012-10-20 Thread Mark H Weaver
Hi Chris, Chris K. Jester-Young cky...@gmail.com writes: On Fri, Oct 12, 2012 at 05:57:11PM -0400, Mark H Weaver wrote: Beyond matters of taste, I don't like this because it makes bugs less likely to be caught. Suppose 'limit' is a computed value, normally expected to be positive. Code that

Re: regexp-split for Guile

2012-10-20 Thread Mark H Weaver
I wrote: (regexp-split + foo bar baz #:limit 3 #:trim 'both) = (foo bar baz) (regexp-split + foo bar baz #:limit 2 #:trim 'both) = (foo bar) Sorry, that last example is wrong of course, but both of these examples raise an interesting question about how

Re: regexp-split for Guile

2012-10-19 Thread Chris K. Jester-Young
On Fri, Oct 12, 2012 at 05:57:11PM -0400, Mark H Weaver wrote: FWIW, I agree with Daniel. I dislike the complicated semantics of this 'limit' argument, which combines into a single number two different concepts: First, I want to thank both Daniel and Mark for their feedback. I'm sorry I

Re: regexp-split for Guile

2012-10-12 Thread Mark H Weaver
Daniel Hartwig mand...@gmail.com writes: On 19 September 2012 03:59, Chris K. Jester-Young cky...@gmail.com wrote: (define* (regexp-split pat str #:optional (limit 0)) […] (reverse (if (zero? limit) (drop-while string-null? final) final Please

Re: regexp-split for Guile

2012-10-04 Thread Ludovic Courtès
Hi Chris, Chris K. Jester-Young cky...@gmail.com skribis: I'm currently implementing regexp-split for Guile, which provides a Perl-style split function (including correctly implementing the limit parameter), minus the special awk-style whitespace handling (that is used with a pattern

Re: regexp-split for Guile

2012-09-18 Thread Sjoerd van Leent Privé
Hi Chris, I have been following your thread about regexp-split. I do have some thoughts about this to make the interface more versalite. So, basically, the Perl split's limit is used this way: 1. Positive limit: Return this many fields at most: (regexp-split : foo:bar:baz:qux: 3)

Re: regexp-split for Guile

2012-09-18 Thread nalaginrut
option of these three implementations) into ice-9? On Mon, 2012-09-17 at 10:01 -0400, Chris K. Jester-Young wrote: Hi there, I'm currently implementing regexp-split for Guile, which provides a Perl-style split function (including correctly implementing the limit parameter), minus the special awk

Re: regexp-split for Guile

2012-09-18 Thread Chris K. Jester-Young
On Tue, Sep 18, 2012 at 09:06:55AM +0200, Sjoerd van Leent Privé wrote: It might just be me, but would it not be more sensible for scheme to just perform the opposite. Return the same amount of fields at most, but starting from the end, thus: (regexp-split : foo:bar:baz:qux: -3) = (foo:bar

Re: regexp-split for Guile

2012-09-18 Thread Chris K. Jester-Young
On Tue, Sep 18, 2012 at 08:59:33PM +0800, nalaginrut wrote: Anyway, if there're so many people like this nice thing, why not we add it (at any option of these three implementations) into ice-9? Oh noes! This is where the bikeshedding begins. ;-) Seriously, I do think having a regexp-split in

Re: regexp-split for Guile

2012-09-18 Thread Chris K. Jester-Young
Here's a revised version, implementing Thien-Thi Nguyen's comments. I added line breaks for the cons and the bottom if (I feel that the top if is still simple enough to keep on the same line). Cheers, Chris. * * * (define (regexp-split-fold match prev) (if

regexp-split for Guile

2012-09-17 Thread Chris K. Jester-Young
Hi there, I'm currently implementing regexp-split for Guile, which provides a Perl-style split function (including correctly implementing the limit parameter), minus the special awk-style whitespace handling (that is used with a pattern of , as opposed to / /, with Perl's split). Attached

Re: regexp-split for Guile

2012-09-17 Thread Thien-Thi Nguyen
() Chris K. Jester-Young cky...@gmail.com () Mon, 17 Sep 2012 10:01:33 -0400 (define (string-empty? str) (zero? (string-length str))) You can use ‘string-null?’ instead. (define* (regexp-split pat str #:optional (limit 0)) (let* ((result (fold-matches pat str '(0)

Re: regexp-split for Guile

2012-09-17 Thread Chris K. Jester-Young
On Mon, Sep 17, 2012 at 09:32:14PM +0200, Thien-Thi Nguyen wrote: (define (string-empty? str) (zero? (string-length str))) You can use ‘string-null?’ instead. Ah, nice! Thanks for the pointer. Style nit: i find it easier to read ‘if’ expressions w/ the condition, then and else