[racket-dev] Very quick poll re `string-trim'

From: Eli Barzilay (eli at barzilay.org)
Date: Fri May 11 07:53:26 EDT 2012

Should (string-trim str sep) remove any number of `sep' matches or
just one?  (This makes no difference for the default `sep' since it's
#px"\\s+".)  Possible options below, feel free to mail me off-list to
reduce noise.

1. Yes.
   * Advantage: makes life with string separator a bit easier.  For
     example, remove only newlines with (string-trim str "\n")
   * Disadvantage: can be confusing with strings or regexps like "xy".
     For example:
       (string-trim ", , foo, bar, " #rx", *") => "foo, bar"

2. No.  Flipped dis/advantages.

3. Yes for string separators, no for (p)regexp separators.  Tries to
   get both advantages, but at the cost of non-uniform behavior.

I'm leaning towards #2 since (a) it's less surprising in the regexp
and >=2 string cases, and (b) it'll make similar to other functions
like `string-split' where an implicit repetition is a bad idea (eg,
when you split with "," you'd usually want that to mean #rx"," not
#rx",+").  OTOH, I hate to loose the possibly useful case of
1-character strings.

          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!

Posted on the dev mailing list.