Modern C++ Lamentations

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sun Dec 30 14:46:14 UTC 2018


On 12/29/18 9:03 PM, Timon Gehr wrote:
> On 29.12.18 10:29, Walter Bright wrote:
>> http://aras-p.info/blog/2018/12/28/Modern-C-Lamentations/
>>
>> Time to show off your leet D skilz and see how good we can do it in D!
> 
> 
> Current D:
> ---
> import std.range, std.algorithm, std.typecons;
> import std.bigint, std.stdio;
> alias then(alias a)=(r)=>map!a(r).joiner;
> void main(){
>      auto triples=recurrence!"a[n-1]+1"(1.BigInt)
>          .then!(z=>iota(1,z+1).then!(x=>iota(x,z+1).map!(y=>tuple(x,y,z))))
>          .filter!((t)=>t[0]^^2+t[1]^^2==t[2]^^2);
>      triples.each!((x,y,z){ writeln(x," ",y," ",z); });
> }
> ---
> 
> tuple-syntax branch at https://github.com/tgehr/dmd/tree/tuple-syntax
> ---
> import std.range, std.algorithm, std.typecons;
> import std.bigint, std.stdio;
> alias then(alias a)=(r)=>map!a(r).joiner;
> void main(){
>      auto triples=recurrence!"a[n-1]+1"(1.BigInt)
>          .then!(z=>iota(1,z+1).then!(x=>iota(x,z+1).map!(y=>(x,y,z))))
>          .filter!((x,y,z)=>x^^2+y^^2==z^^2);
>      triples.each!((x,y,z){ writeln(x," ",y," ",z); });
> }
> ---

The "then" abstraction is pretty awesome. Thanks!


More information about the Digitalmars-d mailing list