Re: [racket-dev] Are There More String Functions?
On 04/18/2012 03:28 PM, Eli Barzilay wrote: `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? string-compress-repeats ? Cheers, Tony _ Racket Developers list: http://lists.racket-lang.org/dev
Re: [racket-dev] Are There More String Functions?
Just now, namekuseijin wrote: > On Wed, Apr 18, 2012 at 4:12 PM, Eli Barzilay 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! _ Racket Developers list: http://lists.racket-lang.org/dev
Re: [racket-dev] Are There More String Functions?
On Wed, Apr 18, 2012 at 4:12 PM, Eli Barzilay 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? why should it take a regexp for the spaces, BTW? (compact-spaces "foobar was here!") should be self-evident without requiring the user to provide the common-sense regex everytime... the `#:trim keyword is a good idea... _ Racket Developers list: http://lists.racket-lang.org/dev
Re: [racket-dev] Are There More String Functions?
Just now, Sam Tobin-Hochstadt wrote: > 'trim' is used in lots of languages for this, and I think we should > stick with that. The issue is a name for the second function that normalizes spaces. (And if you're saying that `trim' is doing both in lots of languages, then that's wrong AFAICT.) > On Apr 18, 2012 3:28 PM, "Eli Barzilay" wrote: > > Just now, Matthias Felleisen wrote: > > > > On Apr 18, 2012, at 3:12 PM, Eli Barzilay wrote: > > > > > `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? > > > > > > string-reduce > > > > ? > > That sounds like a kind of a `fold'... (BTW, some names that I > considered are: `normalize-spaces', `compact-spaces', > `string-normalize'. They all had problems.) > > -- > ((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay: > http://barzilay.org/ Maze is Life! > -- ((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay: http://barzilay.org/ Maze is Life! _ Racket Developers list: http://lists.racket-lang.org/dev
Re: [racket-dev] Are There More String Functions?
'trim' is used in lots of languages for this, and I think we should stick with that. Sam On Apr 18, 2012 3:28 PM, "Eli Barzilay" wrote: > Just now, Matthias Felleisen wrote: > > > > On Apr 18, 2012, at 3:12 PM, Eli Barzilay wrote: > > > > > `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? > > > > > > string-reduce > > > > ? > > That sounds like a kind of a `fold'... (BTW, some names that I > considered are: `normalize-spaces', `compact-spaces', > `string-normalize'. They all had problems.) > > -- > ((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay: >http://barzilay.org/ Maze is Life! > _ Racket Developers list: http://lists.racket-lang.org/dev
Re: [racket-dev] Are There More String Functions?
Just now, Matthias Felleisen wrote: > > On Apr 18, 2012, at 3:12 PM, Eli Barzilay wrote: > > > `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? > > > string-reduce > > ? That sounds like a kind of a `fold'... (BTW, some names that I considered are: `normalize-spaces', `compact-spaces', `string-normalize'. They all had problems.) -- ((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay: http://barzilay.org/ Maze is Life! _ Racket Developers list: http://lists.racket-lang.org/dev
Re: [racket-dev] Are There More String Functions?
On Apr 18, 2012, at 3:12 PM, Eli Barzilay wrote: > `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? string-reduce ? _ Racket Developers list: http://lists.racket-lang.org/dev
Re: [racket-dev] Are There More String Functions?
Yesterday, Sam Tobin-Hochstadt wrote: > I think `racket/string' should provide the useful string functions, > rather than refer users to srfis. The only srfi/13 function I ever > use is `string-trim-both' -- any objection to adding that to > `racket/string'? +1 for this in general, and since the `trim' function is the one that usually leads to this question, it makes sense to add it. I have most done of that now. Some observations: * Looking around, there are two kinds of "customizations" -- the characters that are removed, and which side to remove from (usually in the form of three functions). I'm going with a single `string-trim' function with an optional regexp for the first and `#:left?' and `#:right' keywords for the latter. * It's possible to go with other ways to specify characters, up to srfi-13's use of srfi-14, and this is part of why I didn't add a trim function yet. I now think that it's best to have something that is usually useful (which is by far "just whitespaces") and be done with it. If you need one of these sophisticated things, the `regexp-replace' way is still easy enough. * Another point is the best way to run it efficiently. There was a largish discussion a while ago about various ways to do that (and I happened to have gone through a bunch of options shortly before that too). See also http://blog.stevenlevithan.com/archives/faster-trim-javascript for an overview of options in JS. So in the same spirit as above, I'm just doing something that works reasonably well. (Again, assuming that if speed is really important, then you probably have a good idea on the strings that you're trimming and you can just do whatever works for you directly.) * 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? -- ((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay: http://barzilay.org/ Maze is Life! _ Racket Developers list: http://lists.racket-lang.org/dev