Anonymous Delegates

downs default_357-line at yahoo.de
Tue Jun 17 04:38:45 PDT 2008


Russell Lewis wrote:
> Nick Sabalausky wrote:
>>  That's not what I was referring to. I meant that if you have a 
> function that
>> takes a delegate as a paramater, then it would be nice (if it would
>> even be possible for the language to allow this) to rewrite a call to
>> that function like this:
>>
>> // From this:
>> // (Current method of calling, ugly)
>> repeat(7,
>> {
>>     writefln("Calling Callback");
>> });
>>
>> // To this (Syntactical sugar):
>> // (Not currently allowed, but is it possibly doable?
>> // Much nicer-looking.)
>> repeat(7)
>> {
>>     writefln("Calling Callback");
>> }
> 
> Many people have asked for this; we haven't yet been able to convince
> Walter that it is a good idea.

Afaik, the closest you can come is repeat(7) = { writefln("Calling callback back"); } by making repeat return a struct that overloads opAssign. Or opCat. Or whichever you want.




More information about the Digitalmars-d mailing list