[racket-dev] `string-split'

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Thu Apr 19 08:37:02 EDT 2012

I think Laurent pointed out in his initial message that beginners may be intimidated by regexps. I agree. Plus someone who isn't fluent with regexp may be more comfortable with string-split. Last but not least, a program documents itself more clearly with string-split vs regexp. 

On Apr 19, 2012, at 8:21 AM, Eli Barzilay wrote:

> [Changed title to talk about each one separately.]
> Two hours ago, Laurent wrote:
>> One string function that I often find useful in various scripting
>> languages is a `string-split' (explode in php).  It can be done with
>> `regexp-split', but having something more along the lines of a
>> `string-split' should belong to a racket/string lib I think.  Plus
>> it would be symmetric with `string-join', which already is in
>> racket/ string (or at least a doc line pointing to regexp-split
>> should be added there).
> If you mean something like this:
>  (define (string-split str) (regexp-match* #px"\\S+" str))
> ?
> If so, then I see a much weaker point for it -- unlike other small
> utilities, this one doesn't even compose two function calls.
> The very weak point here is if you want a default argument that
> specifies the gaps to split on rather than the words:
>  (define (string-split str [sep #px"\\s+"])
>    (remove* '("") (regexp-split sep str)))
> but that *does* use regexps, so I don't see the point, still...
> -- 
>          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
>                    http://barzilay.org/                   Maze is Life!
> _________________________
>  Racket Developers list:
>  http://lists.racket-lang.org/dev

Posted on the dev mailing list.