Rather then simply building an array from scratch, perhaps it should be possible to do the following:
auto my_odds = sequence!("n * 2 + 1")()[0...100]
Unless there is another way to do this.
Comment #1 by dmitry.olsh — 2012-04-13T02:33:47Z
Somehow take(sequence!("n * 2 + 1")(), 100) doesn't cut it or what?
Comment #2 by k.hara.pg — 2012-04-13T02:46:20Z
(In reply to comment #0)
> Rather then simply building an array from scratch, perhaps it should be
> possible to do the following:
>
> auto my_odds = sequence!("n * 2 + 1")()[0...100]
>
> Unless there is another way to do this.
With range concept, slicing operator with boundaries has no meaning.
You should use std.range.take and std.array.array like follows:
auto my_odds = array(take(sequence!("n * 2 + 1")(), 100));
And if you use 2.059beta or later, you can use UFCS syntax:
auto my_odds = sequence!("n * 2 + 1")().take(100).array();
Comment #3 by bearophile_hugs — 2012-04-13T04:21:59Z
(In reply to comment #2)
> With range concept, slicing operator with boundaries has no meaning.
I think the point of this enhancement request is to give a meaning to that syntax.
So:
someRange[x .. y]
becomes syntax sugar for calling a function like:
itertools.islice(someRange, x, y)
of Python:
http://docs.python.org/library/itertools.html#itertools.islice
the idea of giving some more syntax support to D lazy ranges isn't that bad.
Comment #4 by dmitry.olsh — 2012-04-13T04:37:09Z
The syntax is supported. It's just up to implementer of a range if he can provide opSlice meaningfully.