guile-devel
[Top][All Lists]
Advanced

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

Re: regexp-split for Guile


From: Chris K. Jester-Young
Subject: Re: regexp-split for Guile
Date: Mon, 17 Sep 2012 16:06:03 -0400
User-agent: Mutt/1.5.21 (2010-09-15)

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 expressions on separate lines.  Similarly ‘cons’.  E.g.:

Right, that sounds like a good idea. It does make the code longer, and
so for simple cases of "if" and "cons", I'd probably still keep it in
one line, but in this case you do make a very clear case with the "cons"
(which involves somewhat lengthier subexpressions).

> A more substantial line of questioning: What happens if ‘regexp-split’
> is called w/ negative ‘limit’?  Should that be handled in ‘regexp-split’
> or will the procs it calls DTRT?  What is TRT, anyway?  In the absence
> of explicit validation, maybe a comment here will help the non-expert.

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)
    => ("foo" "bar" "baz:qux:")

2. Negative limit: Return all fields:

    (regexp-split ":" "foo:bar:baz:qux:" -1)
    => ("foo" "bar" "baz" "qux" "")

3. Zero limit: Return all fields, after removing trailing blank fields:

    (regexp-split ":" "foo:bar:baz:qux:" 0)
    => ("foo" "bar" "baz" "qux")

Because of this, the specific negative value doesn't matter; they are
all treated the same. This is why the code checks for a positive limit
and passes #f to fold-matches if it's not positive. I hope this makes
sense. :-)

Thanks so much for your feedback. I'll incorporate your comments.

Cheers,
Chris.



reply via email to

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