The future of lambda delegates

Bruno Medeiros brunodomedeiros+spam at com.gmail
Fri Aug 18 06:36:51 PDT 2006


xs0 wrote:
> Mikola Lysenko wrote:
>> [snip]
>> Any thoughts or comments?
> 
> Well, to me it seems that anything the compiler will try to do 
> automatically will be wrong (or at least needlessly slow) in many cases. 
> And a lot of the problem seems to be simply that one can't attach 
> storage to a delegate without creating a whole class/struct, and doing 
> that is too verbose to be used easily/often.
> 
> So, why not simply have some syntax sugar for that?
> 
> int delegate() fibs()
> {
>     int a=0, b=1;
>     return delegate with(a,b) { // it takes a and b with it
>         ...
>     }
> }
> 
> Which would become exactly what you proposed.
> 
> 
> xs0

Would the instances of a & b of the fibs function be the same as the 
ones in the delegate? In other words, does the "with(a,b)" create a heap 
copy of a & b, for the delegate to use, or does it cause the original 
"int a=0, b=1;" to be heap allocated?


-- 
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d mailing list