Carmack about static analysis

Timon Gehr timon.gehr at gmx.ch
Sun Dec 25 15:16:50 PST 2011


On 12/25/2011 11:53 PM, Timon Gehr wrote:
> On 12/25/2011 02:44 PM, simendsjo wrote:
>> On 25.12.2011 00:44, Timon Gehr wrote:
>>>
>>> Not really. Functional style code tends to be conceptually simpler.
>>> Having code that is more readable can help. Getting rid of (({return
>>> {return}}){return()}) makes the code more readable, whereas excessively
>>> shortening identifiers does the opposite.
>>>
>>> See here for an example of what bearophile is talking about:
>>> http://pastebin.com/2rEdx0RD
>>
>> r=cons(st(1UL),cons(st(1UL),lz({return zipWith((Lazy!ulong a,Lazy!ulong
>> b){return lz({return a()+b();});},r,r().tail)();})));
>>
>
> http://pastebin.com/C6vf9DQQ
>
> r=cons(st(cast(T)1),lz({return merge(merge(map((Lazy!T a){return
> lz({return 2*a();});},r),map((Lazy!T a){return lz({return
> 3*a();});},r)),map((Lazy!T a){return lz({return 5*a();});},r))();}));
>
> D'oh!

With UFCS and alternate delegate syntax:

r=st(cast(T)1).cons(lz(=> r.map((Lazy!T a)=> lz(=> 2*a()))
                    .merge(r.map((Lazy!T a)=> lz(=> 3*a())))
                    .merge(r.map((Lazy!T a)=> lz(=> 5*a())))()
                ));


With delegate parameter type inference for non-template delegate type 
parameters (as proposed by Andrei in a recent bug report):

r=st(cast(T)1).cons(lz(=> r.map((a)=> lz(=> 2*a()))
                    .merge(r.map((a)=> lz(=> 3*a())))
                    .merge(r.map((a)=> lz(=> 5*a())))()
                ));


With language support for non-strict evaluation:

@nonstrict:

r=cast(T)1
     .cons(
                  r.map((a)=> 2*a)
           .merge(r.map((a)=> 3*a))
           .merge(r.map((a)=> 5*a))
     );










More information about the Digitalmars-d mailing list