Recursive delegate inside template?

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Jun 26 16:14:36 UTC 2020


On Fri, Jun 26, 2020 at 02:12:00PM +0000, drathier via Digitalmars-d-learn wrote:
> I'm trying to get this to compile, without much luck:
> 
> ```
> bool foo()
> {
>     template fn(A)
>     {
>         A delegate(A) fn;
>         fn = delegate A(A a)
>         {
>             return fn(a);
>         };
>     }
> 
>     return fn!(bool)(true);
> }
> ```
> 
> What am I missing here? How can I define a recursive delegate inside
> another function like this?
[...]

Sounds like you're looking for the equivalent of the Y combinator,
perhaps?

	https://en.wikipedia.org/wiki/Fixed-point_combinator#Y_combinator


T

-- 
Never trust an operating system you don't have source for! -- Martin Schulze


More information about the Digitalmars-d-learn mailing list