Delegates
Frits van Bommel
fvbommel at REMwOVExCAPSs.nl
Fri Jan 19 04:23:38 PST 2007
Robin Allen wrote:
> I'm trying to figure out delegates. From what I can see, they're intended to be what other languages call closures?
>
> So, say I wanted to write some functions for signal processing. I'd define a Wave type as a function of time, like this:
>
> alias float delegate(float) Wave;
>
> and a function to return a sine wave of a specified frequency like this:
>
> Wave sine(float freq)
> {
> return delegate(float t) { return std.math.sin(2*std.math.PI*t); };
> }
[Snipped some similar examples]
Returning delegate literals is never a good idea.
A recent thread "Trouble with anon delegates." should explain the issue.
I suggest you read it :).
More information about the Digitalmars-d-learn
mailing list