[Top][All Lists]

[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: Tue, 18 Sep 2012 15:31:25 -0400
User-agent: Mutt/1.5.21 (2010-09-15)

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" "baz" "qux" "")

Unfortunately, this is not ideal to implement:

1. Regexes are inherently forward-searching only. This means that
   matches are always built up from left-to-right.

2. Thus, there is no sensible way to implement right-fold-matches,
   which is what would be required for what you're proposing. What
   would instead have to happen is that you have to do list-matches
   with no limit, then ignore the front matches. This complicates
   the code significantly.

3. It's not compatible with Perl's split limits. The appeal of the
   Perl semantics is that it's already implemented exactly the same
   way in Ruby and Java, so the learning curve is lower.

> The problem described in your second case could be solved by using a
> symbol, such as #:all, or something similar.

I'm not a fan of this. :-( Because then you'd have to add another
keyword, like #:trim, to trim off the blanks (which is what happens with
a limit of 0), and then the interface suddenly got a lot more verbose.

Wanting all the fields, or trimming blank ones, are the commonest use
cases, and people who want to use it should not be punished with having
to use a verbose syntax for it.

Thanks for your feedback! Unfortunately, it sounds like implementing it
would complicate things too much, in my opinion. :-( YMMV.


reply via email to

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