array slicing currently does not support steps?
d.forum at webfreak.org
Tue Aug 4 08:36:54 UTC 2020
On Tuesday, 4 August 2020 at 00:03:16 UTC, mw wrote:
> On Monday, 3 August 2020 at 23:50:45 UTC, Paul Backus wrote:
>> On Monday, 3 August 2020 at 23:32:29 UTC, mw wrote:
>>> I just noted that D array slice does not support steps?
>> You can use std.range.stride for this:
> OK, good to know.
> But if it's built into the language syntax (as extended array
> slicing), it will be better: more succinct, and much easier for
> Python programmers to adopt D.
just act like this is syntax in the language and not a function
auto x = array[0 .. 10].stride(2);
I think readability-wise this beats other syntax you can come up
with and it's just a library solution :)
If you then want to copy it into an actual array you can pass as
auto x = array[0 .. 10].stride(2).array;
or adjust your functions to handle ranges properly :p
On the function implementation side I can definitely see room for
improvement though, like the signatures DIP rikkimax had once
made which would make templates not needed for supporting passing
and storing ranges.
More information about the Digitalmars-d