The future of lambda delegates

kris foo at bar.com
Wed Aug 16 11:02:46 PDT 2006


Oskar Linde wrote:
> kris wrote:
> 
> 
>>Yeah, this is a serious trap for the unwary and, unfortunately,
>>prohibits the use of such delegates in the one place where the elegance
>>would be most notable: as gui callbacks, per your example. As you say,
>>the way around it (currently) is to create a class to house the 'scope'
>>content, or otherwise refer to it. That's unweildy, even with
>>anonymous-class syntax.
>>
>>If, as you suggest, D had some means to indicate that the scope should
>>be placed on the heap instead of the stack, it would resolve the concern
>>nicely. Perhaps that indication might be lambda syntax itself? For
>>example, in C# the lambda indicator is the symbol '=>'
> 
> 
> I don't think any special syntax is needed. I believe the compiler could be
> able to automatically identify whether a function may have escaping
> delegates referring to local variables. 
> 
> /Oskar
> 

Yes, that's certainly one way. But the suggestion was to "take 
advantage" of an even simpler form of lambda delegates; one that C# 3.0 
is moving toward. It's worth taking a look at, just for comparitive 
purposes? Two random links:

http://www.interact-sw.co.uk/iangblog/2005/09/30/expressiontrees
http://www.developer.com/net/csharp/article.php/3598381

On the other hand, one of the great things about the D compiler is it's 
voracious speed. If it turns out that automagically trying to figure out 
where the 'escapees' are will noticably slow the compiler down, then a 
bit of syntactic sugar might make all the difference :)




More information about the Digitalmars-d mailing list