Re: more naming

2011-01-22 Thread Nick Sabalausky
"Andrei Alexandrescu" wrote in message news:ihf0kc$2fqj$1...@digitalmars.com... > OK, so we have replace(haystack, needle, nail) which replaces _all_ > occurrences of needle in haystack with nail. How would you call a function > that replaces only the _first_ occurrence of needle with nail? > >

Re: more naming

2011-01-22 Thread Paul D. Anderson
Daniel Gibson Wrote: > Am 22.01.2011 18:46, schrieb Andrei Alexandrescu: > > On 1/22/11 11:38 AM, Torarin wrote: > >> 2011/1/22 Andrei Alexandrescu: > >>> OK, so we have replace(haystack, needle, nail) which replaces _all_ > >>> occurrences of needle in haystack with nail. How would you call a > >

Re: more naming

2011-01-22 Thread Andrej Mitrovic
On 1/22/11, spir wrote: > In years and years of string processing, I have used maxreplace once, I > guess, and the value was not 1. Isn't Andrei talking about std.algorithm.replace, which should work with any range and not just strings?

Re: more naming

2011-01-22 Thread spir
On 01/22/2011 05:27 PM, Andrei Alexandrescu wrote: OK, so we have replace(haystack, needle, nail) which replaces _all_ occurrences of needle in haystack with nail. How would you call a function that replaces only the _first_ occurrence of needle with nail? Must be a distinct function, not a runt

Re: more naming

2011-01-22 Thread bearophile
Daniel Gibson: > IMHO replace (without eny suffix) sounds like it replaces every occurence. > So just add replaceFirst for a function that replaces only the first > occurence :) OK. Bye, bearophile

Re: more naming

2011-01-22 Thread Torarin
2011/1/22 Andrei Alexandrescu : > That's what I'm fearing - changing current replace to replaceAll and adding > replace with the meaning of replaceFirst would silently change the semantics > of existing code. > > Andrei > Yeah, I see that problem. I'm just so used to "replace first" being the def

Re: more naming

2011-01-22 Thread Adam D. Ruppe
Torarin wrote: > It sounds like the current replace should be named replaceAll. That would break lots of existing code, and it doesn't seem to fit. If replacing only the first element means it can take a special range, whereas all other n is is the same, it seems obvious that replaceFirst be the

Re: more naming

2011-01-22 Thread Daniel Gibson
Am 22.01.2011 18:46, schrieb Andrei Alexandrescu: On 1/22/11 11:38 AM, Torarin wrote: 2011/1/22 Andrei Alexandrescu: OK, so we have replace(haystack, needle, nail) which replaces _all_ occurrences of needle in haystack with nail. How would you call a function that replaces only the _first_ occu

Re: more naming

2011-01-22 Thread Andrei Alexandrescu
On 1/22/11 11:38 AM, Torarin wrote: 2011/1/22 Andrei Alexandrescu: OK, so we have replace(haystack, needle, nail) which replaces _all_ occurrences of needle in haystack with nail. How would you call a function that replaces only the _first_ occurrence of needle with nail? Must be a distinct fun

Re: more naming

2011-01-22 Thread so
It sounds like the current replace should be named replaceAll. Torarin replaceAll replaceN replaceFirst replaceLast

Re: more naming

2011-01-22 Thread Torarin
2011/1/22 Andrei Alexandrescu : > OK, so we have replace(haystack, needle, nail) which replaces _all_ > occurrences of needle in haystack with nail. How would you call a function > that replaces only the _first_ occurrence of needle with nail? > > Must be a distinct function, not a runtime paramete

Re: more naming

2011-01-22 Thread Andrei Alexandrescu
On 1/22/11 11:03 AM, Justin Johansson wrote: On 23/01/11 03:27, Andrei Alexandrescu wrote: OK, so we have replace(haystack, needle, nail) which replaces _all_ occurrences of needle in haystack with nail. How would you call a function that replaces only the _first_ occurrence of needle with nail?

Re: more naming

2011-01-22 Thread Andrei Alexandrescu
On 1/22/11 10:47 AM, Andrej Mitrovic wrote: What if you want to replace a _count_ number of occurrences of needle in haystack with nail? That's what Python's replace does, although I think that only works for strings in Python. A specific count is rare but can be added as a defaulted parameter.

Re: more naming

2011-01-22 Thread Justin Johansson
On 23/01/11 03:27, Andrei Alexandrescu wrote: OK, so we have replace(haystack, needle, nail) which replaces _all_ occurrences of needle in haystack with nail. How would you call a function that replaces only the _first_ occurrence of needle with nail? Must be a distinct function, not a runtime p

Re: more naming

2011-01-22 Thread Andrej Mitrovic
What if you want to replace a _count_ number of occurrences of needle in haystack with nail? That's what Python's replace does, although I think that only works for strings in Python.

more naming

2011-01-22 Thread Andrei Alexandrescu
OK, so we have replace(haystack, needle, nail) which replaces _all_ occurrences of needle in haystack with nail. How would you call a function that replaces only the _first_ occurrence of needle with nail? Must be a distinct function, not a runtime parameter to the existing function. This is b