System programming in D (Was: The God Language)

Peter Alexander peter.alexander.au at gmail.com
Thu Jan 5 15:40:11 PST 2012


On 5/01/12 10:17 PM, Iain Buclaw wrote:
> On 5 January 2012 22:11, Manu<turkeyman at gmail.com>  wrote:
>> So regarding my assumptions about translating the D front end expressions to
>> GCC? Is that all simpler than I imagine?
>> Do you think GDC generates optimal code comparable to C code?
>>
>> What about pure functions, can you make good on optimisations like caching
>> results of pure functions, moving them outside loops, etc?
>>
>>
>
> I think you are confusing the pure with memoization.  I could be wrong
> however... :)
>

I think Manu is right:

void foo(int x)
{
     int[10] a;
     foreach (ref e; a)
         e = bar(x);
}

If bar is pure then you can safely transform this into:

void foo(int x)
{
     int[10] a;
     auto barx = bar(x);
     foreach (ref e; a)
         e = barx;
}

If bar is not pure then this transformation would be unsafe.


More information about the Digitalmars-d mailing list