Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Tango.core.Array.find with additional start parameter

Moderators: larsivi

Posted: 09/27/07 16:12:40 Modified: 09/27/07 16:13:14

Hi,

I like to ask if it makes sense to ask for an additional start parameter for Array.core.find. Instead of:

pos = start + find(str[start..$], (char c){ return c == 'x'});

we could write:

pos = find(str,(char c){ return c == 'x'}, start);

It looks cleaner to do it this way. Less like a workaround. A default parameter (.., uint start = 0) also wouldn't break any code.

Worth a ticket, or was it already discussed?

Author Message

Posted: 09/27/07 16:55:24

I'd originally expected slices to be used in places where offsets are needed. I suppose my worry is that if I add an offset param for find then I'd have to add one for basically every other routine in core.Array as well. Still, I suppose it's worth considering.

As an aside, this is also legal and looks a bit better:

pos = start + str[start..$].findIf((char c){ return c == 'x'});

Posted: 09/27/07 16:59:17

slices are certainly more elegant (and more D-like) ...

Posted: 09/27/07 18:45:19

pos = start + str[start..$].findIf((char c){ return c == 'x'});

ha, I wasn't aware that this works outside the module scope of findIf. :))

Slices may be more elegant for .. slices, but it also means that we create a different value/context.

The return value must be converted back into the original context.
That doesn't seems to be very elegant to me.

An offset is more elegant imo, because the code looks simpler.
Imho, an offset would also result in slightly faster code.

Anyway, I agree with sean that adding an offset to one function would lead to do the same for all these functions.