Is there a way for a function to return itself in D?

Lars Kyllingstad public at kyllingen.NOSPAMnet
Tue Oct 14 05:45:34 PDT 2008


Lars Kyllingstad wrote:
> Simen Kjaeraas wrote:
>> Like the subject says, I wonder if it's possible for a function to 
>> return itself.
>> No matter how I think of this, I end up with an endless recursive 
>> function
>> declaration. Creating a functor that does this is simple, so why not a 
>> function?

[...]

> But it's kinda ugly, what with the casts and all. I don't see that it is 
> useful either. It makes sense to return a functor, because it is an 
> object and has state. A function is stateless, so any "reference" to the 
> function will be identical.

Ah, I just thought of the obvious use case: Chaining function calls. In 
which case my previous post won't be useful at all.

-Lars


More information about the Digitalmars-d-learn mailing list