[racket-dev] `racket/string' extensions

From: David Vanderson (david.vanderson at gmail.com)
Date: Thu Apr 19 14:57:06 EDT 2012

Thank you so much for this.  This was definitely one area of difficulty 
when I started using Racket for scripting.

On 04/19/2012 09:28 AM, Eli Barzilay wrote:
> But to allow other uses, make these arguments a string *or* a regexp,
> where a regexp is taken as-is.  This leads to another simplicity point
> in this design:
This is fantastic.
>    (string-split str [sep #px"\\s+"])
>      Splits `str' on occurrences of `sep'.  Unclear whether it should
>      do that with or without trimming, which affects keeping a
>      first/last empty part.  [*1*] Possible solution: make it take a
>      `#:trim?' keyword, in analogy to `string-normalize-spaces'.  This
>      would make `#t' the obvious choice for a default, which means that
>        (string-split ",,foo, bar," ",") ->  '("foo" " bar")
I like the #:trim? keyword, but I would suggest defaulting to #f.  Many 
of my uses of string-split would be doing simple parsing of delimited 
input, and it seems to me that trimming by default would be non-obvious.
>    (string-index str sub [start 0] [end (string-length str)])
>      Looks for occurrences of `sub' in `str', returns the index if
>      found, #f otherwise.  [*2*] I'm not sure about the name, maybe
>      `string-index-of' is better?
Either sounds fine, so I'd go with string-index just because it's shorter.
>    (list-index list elt)
>      Looks for `elt' in `list'.  This is a possible extension for
>      `racket/list' that would be kind of obvious with adding the above.
>      [*3*] I'm not sure if it should be added, but IIRC it was
>      requested a few times.  If it does get added, then there's another
>      question for how far the analogy goes: [*3a*] Should it take a
>      start/end index too?  [*3b*] Should it take a list of elements and
>      look for a matching sublist instead (which is not a function that
>      is common to ask for, AFAICT)?
How do people do this now?


Posted on the dev mailing list.