[racket-dev] `string-split'

From: Laurent (laurent.orseau at gmail.com)
Date: Thu Apr 19 09:13:56 EDT 2012

Continuing with this line, it seems that a better definition is as
> follows:
>
>  (define (string-split str [sep " "])
>    (remove* '("") (regexp-split (regexp-quote (or sep " ")) str)))
>
> Except that the full definition could be a bit more efficient.
>
> Three questions:
>
> 1. Laurent: Does this make more sense?
>

Yes, this definitely makes more sense to me.
It would then treat (string-split "aXXbXXXXy" "X") just like the " " case.

Although if you want to find the columns of a latex line like "x && y & z"
you will have the wrong result.
Maybe use an optional argument to remove the empty strings? (not sure)


> 2. Matthew: Is there any reason to make the #f-as-default part of the
>   interface?  (Even with the new reply I don't see a necessity for
>   this -- if the target is newbies, then I think that keeping it as a
>   string is simpler...)
>

There is probably no need for #f with the new spec.

4. Related to Q3: what does "xy" as that argument mean exactly?
>   a. #rx"[xy]"
>   b. #rx"[xy]+"
>   c. #rx"xy"
>   d. #rx"(?:xy)+"
>

Good question. d. would be the simplest case for newbies, but b. might be
more useful.
I think several other languages avoid this issue by using only one
character as the separator.

Laurent
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/dev/archive/attachments/20120419/a28c4974/attachment.html>

Posted on the dev mailing list.