[racket-dev] `string-split'

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Thu Apr 19 08:53:07 EDT 2012

At Thu, 19 Apr 2012 14:43:44 +0200, Laurent wrote:
> On Thu, Apr 19, 2012 at 14:33, Matthew Flatt <mflatt at cs.utah.edu> wrote:
> 
> > I agree with this: we should add `string-split', the one-argument case
> > should be as Eli wrote,
> 
> 
> About this I'm not sure, as one cannot reproduce this behavior by providing
> an argument (or it could make the difference between string-as-not-regexps
> and regexps? Wouldn't this be different from other places?).

I'm suggesting that supplying `#f' as the argument would be the same as
not supplying the argument.

It is a special case, though. I don't mind the specialness here,
because I see the job of `string-split' as making a couple of useful
special cases easy (as opposed to the generality of `regexp-split').


> It would then appear somewhat magical. To me the " " default splitter seems
> more intuitive.
> 
> Laurent
> 
> 
> > and the two-argument case should be as Laurent
> > wrote. (Probably the optional second argument should be string-or-#f,
> > where #f means to use #px"\\s+".)
> >
> > At Thu, 19 Apr 2012 14:30:31 +0200, Laurent wrote:
> > >  (define (string-split str [sep #px"\\s+"])
> > > >    (remove* '("") (regexp-split sep str)))
> > > >
> > >
> > > Nearly, I meant something more like this:
> > >
> > > (define (string-split str [splitter " "])
> > >   (regexp-split (regexp-quote splitter) str))
> > >
> > > No regexp from the user POV, and much easier to use with little
> > knowledge.
> > > _________________________
> > >   Racket Developers list:
> > >   http://lists.racket-lang.org/dev
> >

Posted on the dev mailing list.