Recursive Declarations (for functions).
BCS
ao at pathlink.com
Sat Aug 25 21:02:32 PDT 2007
Reply to Leandro,
nt
> Hi. I was designing a FSM and I wanted to use a simple scheme where a
> state is represented with a function which returns a pointer to the
> next state (function) when I realized there is no support in the
> language to declare a function that returns a function with the same
> signature as itself.
>
> Here is an explanation of the problem and suggested solutions for C++:
> http://www.gotw.ca/gotw/057.htm
>
> AFAIK you can implement something similar in D, but D doesn't have a
> "native" solution either.
>
> What I want to know is if it's even posible to have a nice syntax to
> support this, something like:
>
> fp function() fp;
>
> Is the type system capable of handling this?
>
ROFL
I was playing with almost exactly this yesterday and tried this
alias R delegate() R;
and found a bug in DMD where you get a stack overflow from it. DMD gives
you a "recursive alias declaration" error (about 500+ of them actually) but
I can think of no reason that it shouldn't be allowed to work. it would allow
a hole slew of interesting things
alias T[int] T;
alias Container!(T) t;
More information about the Digitalmars-d
mailing list