Fabian Claßen admin at
Tue Dec 2 12:12:09 PST 2008

Jarrett Billingsley schrieb:
> On Tue, Dec 2, 2008 at 2:45 PM, 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.
> It's legal.  If you have a typesafe variadic array of delegates, you
> can call the function as if it took a bunch of lazy parameters.

I am learning D. But ...
I worked with other programming languages before and so I learn D with a 
book for experienced programmers. My learning concept is like:
reading ... memorizing ... coding
So there was a very similar code in the book and I tried to write this 
code by heart.
That's only for your information why I've writen the code like this.

The function gets a list of lazy arguments and summarizes the arguments.

Greetings Fabian Claßen

PS: Sorry I believe my english is bad - I am German :D lol

-------------- next part --------------
A non-text attachment was scrubbed...
Name: admin.vcf
Type: text/x-vcard
Size: 190 bytes
Desc: not available
URL: <>

More information about the Digitalmars-d mailing list