To write such an expressive code D

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Feb 9 12:16:45 PST 2015


On 02/09/2015 12:05 PM, Dennis Ritchie wrote:
> On Monday, 9 February 2015 at 20:03:00 UTC, Vladimir Panteleev wrote:
>> On Monday, 9 February 2015 at 19:57:23 UTC, Ali Çehreli wrote:
>>>    writefln("%(%.15g\n%)", sins);
>>
>> In 2.067, you can write:
>>
>> iota(0, PI/2, PI/2/9).map!sin.each!writeln;
>
> March 1!

Yes, but apparently D's default precision for output is less than F#'s 
so how about the following? :p

     "%(%.15g\n%)".writefln(iota(0, PI/2, PI/2/9).map!sin);

Just for demonstration, I would not write anything like that but the 
following is fine because now the format becomes the second parameter: :)

     iota(0, PI/2, PI/2/9).map!sin.writeF("%(%.15g\n%)");

void writeF(R)(R range, string format)
{
     return writefln(format, range);
}

Ali



More information about the Digitalmars-d-learn mailing list