To write such an expressive code D

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Feb 9 11:57:23 PST 2015


On 02/09/2015 11:45 AM, Tobias Pankrath wrote:

> iota(0, 91, 10).map!sin.writeln
>
> or something like that.

Yes: :)

import std.math;
import std.stdio;
import std.range;
import std.algorithm;

void main()
{
     const beg = 0.0L;
     const interval = PI_2 / 9;
     const end = PI_2 + interval;

     auto sins = iota(beg, end, interval).map!sin;
     writefln("%(%.15g\n%)", sins);
}

0
0.17364817766693
0.342020143325669
0.5
0.642787609686539
0.766044443118978
0.866025403784439
0.939692620785908
0.984807753012208
1

Ali



More information about the Digitalmars-d-learn mailing list