Delegate

Derek Parnell derek at psych.ward
Tue Dec 2 12:42:12 PST 2008


On Tue, 02 Dec 2008 22:53:25 +0300, Denis Koroskin wrote:

> On Tue, 02 Dec 2008 22:45:03 +0300, Derek Parnell <derek at psych.ward> wrote:
> 
>> On Tue, 02 Dec 2008 19:30:47 +0100, Fabian Claßen wrote:
>>
>>> Hi
>>> I have a problem:
>>>
>>> What's wrong about this code?
>>> Code:
>>>
>>> import std.stdio;
>>>
>>> int main() {
>>> 	writefln("%f", add(100, 786, 56.0));
>>> 	return 0;
>>> }
>>>
>>> double add(double delegate()[] dgs...) {
>>> 	double result = 0;
>>> 	foreach(double delegate() dg; dgs) {
>>> 		result += dg;
>>> 	}
>>> 	return result;
>>> }
>>>
>>> Or a better question is: How can I get the value out of the delegate?
>>
>> I don't understand your code, sorry. It seems to me that the argument you
>> supplied to add() is a list of doubles and not a list of delegates.
>>
>>
> 
> I was a bit surprized at first, too, but any value is indeed a lazy  
> delegate that returns itself.

And they C++ has some arcane rules :-)!!!

-- 
Derek Parnell
Melbourne, Australia
skype: derek.j.parnell



More information about the Digitalmars-d mailing list