[racket-dev] Are There More String Functions?

From: Eli Barzilay (eli at barzilay.org)
Date: Wed Apr 18 17:08:55 EDT 2012

Just now, namekuseijin wrote:
> On Wed, Apr 18, 2012 at 4:12 PM, Eli Barzilay <eli at barzilay.org> wrote:
> > * Finally, I'm also adding a related function:
> >  `string-normalize-spaces', which takes a string and a regexp for the
> >  spaces, and turns all spaces into single ones.  Same principles as
> >  above.  This one is getting a `#:trim?' keyword that says whether
> >  spaces at the edges should be dropped (the default) or normalized.
> >
> >  BTW, I hate that name -- it makes the `string-' prefix looks even
> >  uglier...  Any suggestions for a better name?
> 
> compact-spaces?  Why should all functions have a type prefix?  How
> many functions could be possibly named normalize-spaces not dealing
> with strings?

That's a convention in `racket/string', derived from a general
convention for non-list functions.


> why should it take a regexp for the spaces, BTW?

Because it's easy to specify, mostly.


> (compact-spaces "foobar was               here!")
> 
> should be self-evident without requiring the user to provide the
> common-sense regex everytime...

It defaults to #px"\\s", so that would work fine.

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


Posted on the dev mailing list.