<br><br><div class="gmail_quote">On Thu, May 24, 2012 at 10:45 PM, Eli Barzilay <span dir="ltr"><<a href="mailto:eli@barzilay.org" target="_blank">eli@barzilay.org</a>></span> wrote: <br><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div class="im"><br>
> (string-index str sub [start 0] [end (string-length str)])<br>
> Looks for occurrences of `sub' in `str', returns the index if<br>
> found, #f otherwise. [*2*] I'm not sure about the name, maybe<br>
> `string-index-of' is better?<br></div></blockquote><div><br>Maybe `string-find'?<br> </div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div class="im">
> (list-index list elt)<br>
> Looks for `elt' in `list'. This is a possible extension for<br>
> `racket/list' that would be kind of obvious with adding the above.<br>
> [*3*] I'm not sure if it should be added, but IIRC it was<br>
> requested a few times. If it does get added, then there's another<br>
> question for how far the analogy goes: [*3a*] Should it take a<br>
> start/end index too? [*3b*] Should it take a list of elements and<br>
> look for a matching sublist instead (which is not a function that<br>
> is common to ask for, AFAICT)?<br></div></blockquote><div><br>3b: I think that's over-complicating things, personally.<br> </div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div class="im">
</div>
2. Another subtle point is what should these return:<br>
<br>
(string-trim "aaa" "aa")<br>
(string-trim "ababa" "aba") </blockquote><div> </div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
After deliberating on that, I eventually made it return ""<br>
because it seems like that would be more expected. </blockquote><div><br>That this could return "" surprised me. The intuitive behavior to me is
the following: If you remove "aa" from "aaa", you get "a", and if you
repeat it (from either side), you don't match and return "a".<br>
This relies on an occidental left->right preference though.<br>
<br>
But as you say, these are rare cases, so it could well be left as
"unspecified" or specified in the simplest way to implement, as long as
it is well documented?<br><br> </div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">(But that's<br>
really a subtle point, since multi-character string separators<br>
are very rare anyway.) I also looked into several of these<br>
functions, but there's no precedent that I've seen either way.<br>
(In many cases it uses a regexp or uses the `sep' string as a bag<br>
of characters.)<br>
<br>
As a corollary of this, I thought that it might also mean that<br>
this should happen:<br>
<br>
(string-split "x---y---z" "--") => '("x" "y" "z")<br>
<br>
but in this case it looks like this wouldn't be expected.<br></blockquote><div><br>Indeed.<br> </div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Perhaps a hand-wavy proof of this is that coding this behavior<br>
would take a little effort (need to look for all occurrences of<br>
the pattern) whereas in the `string-trim' case the above is very<br>
easy (find the start and end, return "" if start >= end). </blockquote><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
* (string-split str [sep #px"\\s+"] #:trim? [trim? #t] #:repeat? [+? #f])<br>
<br>
As discussed.<br>
<br>
* (string-normalize-spaces str [sep #px"\\s+"] [space " "]<br>
#:trim? [trim? #t] #:repeat? [+? #f])<br></blockquote><div><br>Side comment: If it's possible, formatting the signature like this in the docs could be a good idea: put all the keyword arguments on another line, so that the most important and often used options are put forward. I think that might help newbies to understand the question (keywords can be a bit frightening maybe? (not sure)).<br>
<br></div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
I ended up keeping the name of this. Also, it's easy to implement<br>
directly as<br>
<br>
(string-join (string-split str sep ...) space)<br></blockquote><div><br>That's a good sign that the functions have the correct (default) behavior.<br><br></div></div>Looking forward to use all these!<br><br>Laurent<br>