[racket-dev] `racket/string' extensions

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

I like it a lot.


>  (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")

A keyword might be a good idea indeed.

>  (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)?

Or should it take a comparison operator (e.g., defaulting to equal?) ?
Maybe list-index could be simple (considering the list flat), and
list-index* could return a list of positions in the sublists?
E.g., (list-index* '(a (b (c d) e) f) 'c) -> '(1 1 0)
(list-index* '(a (b (c d) e) f) '(c d)) -> '(1 1)

Btw, from time to time I wish that `remove*' accepted a single element that
is not a list.
I find it a bit cumbersome and not good looking to wrap a single value in a
(list ...).
Since modifying remove* would probably break a few things, maybe a remove+ ?

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

Posted on the dev mailing list.