Carmack about static analysis

Timon Gehr timon.gehr at
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:
>> r=cons(st(1UL),cons(st(1UL),lz({return zipWith((Lazy!ulong a,Lazy!ulong
>> b){return lz({return a()+b();});},r,r().tail)();})));
> 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(=>!T a)=> lz(=> 2*a()))
                    .merge(!T a)=> lz(=> 3*a())))
                    .merge(!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(=>> lz(=> 2*a()))
                    .merge(> lz(=> 3*a())))
                    .merge(> lz(=> 5*a())))()

With language support for non-strict evaluation:


        > 2*a)
           .merge(> 3*a))
           .merge(> 5*a))

More information about the Digitalmars-d mailing list