std.string.indexOf with an optional start-at parameter?
KennyTM~
kennytm at gmail.com
Sun Apr 3 12:46:46 PDT 2011
On Apr 4, 11 02:29, Aleksandar Ružičić wrote:
> On Sun, Apr 3, 2011 at 8:16 PM, Andrei Alexandrescu
> <SeeWebsiteForEmail at erdani.org> wrote:
>> It's not.
>
> Seems I've missed that in the docs, I tought it will always make a copy :)
>
>> I think that's a natural and simple improvement of indexOf. The one aspect
>> that I'm unsure about is starting from the end for negative indices.
>
> Negative indices might seem a bit odd but it's standard in other
> languages (like javascript and php which I've already mentioned).
> I would even like to see this in D:
>
You mean Python and Ruby.
- Javascript does not support negative index. In fact, JS has no true
arrays, it only has associative array.
- PHP does not support negative index. http://ideone.com/8MZ2T
Many other languages that I've heard of like C#, C, C++, Go, Haskell and
Java also do not support negative index.
Also, interestingly, Perl 5 had negative index, but Perl 6 killed it.
(http://perlcabal.org/syn/S09.html#Negative_and_differential_subscripts)
"The Perl 6 semantics avoids indexing discontinuities (a source of
subtle runtime errors), and provides ordinal access in both
directions at both ends of the array."
This does not mean negative index is useless (I use it all the time when
programming in Python), but D shouldn't add a feature just because other
languages have it, or even you think that language had it.
> array[-2]; // get 'a' from "foobar"
>
> same for slicing:
>
> array[-4..2]; // get "ob" from "foobar"
>
>> Could you please submit an enhancement request to bugzilla?
>
> sure!
More information about the Digitalmars-d
mailing list