ranges reading garbage
bearophile via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Feb 15 10:57:06 PST 2015
FG:
> Odd... Still something is wrong. It prints:
> [0, 4, 5, 1, 1, 5, 6, 2, 2, 6, 7, 3, 4, 8, 9, 5, 5, 5, 6, 6, 6,
> 6, 7, 7]
>
> instead of this:
> [0, 4, 5, 1, 1, 5, 6, 2, 2, 6, 7, 3, 4, 8, 9, 5, 5, 9, 10, 6,
> 6, 10, 11, 7]
This is less lazy and gives another result:
import std.range, std.algorithm, std.stdio;
void foo(in float[] data, in float[] xs, in float[] ys) @safe {
iota(0, data.length, ys.length)
.map!(xBase => iota(xBase, xBase + ys.length - 1)
.map!(y => [y, y+ys.length, y+ys.length+1,
y+1])
.join)
.join
.writeln;
}
void main() {
foo([1,2,3,4,5,6,7,8], [0.1,0.2], [10,20,30,40]);
}
What a fun program :-)
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list