Calling nested function before declaration

Walter Bright newshound2 at digitalmars.com
Thu Sep 27 20:28:09 UTC 2018


On 9/27/2018 11:33 AM, Timon Gehr wrote:
> The current behavior is easy to specify and simple to implement, and it is what 
> Walter has implemented. A better behavior that is almost as simple to implement 
> would be to insert nested functions into the symbol table in blocks of 
> back-to-back-defined nested functions, but that would be a breaking language 
> change at this point. (Maybe you can get a DIP though though.) Otherwise, the 
> template workaround is a bit ugly but it works and is non-intrusive.

Right. Functions tend to be short, and it's very rare that a function cannot be 
defined before use. One such case is mutually recursive functions. But as Timon 
showed, there is a simple workaround for this, and has been suggested, a 
delegate can be used, too.

And as Timon also suggested, the straightforwardness of the existing approach is 
an advantage and is intended.


More information about the Digitalmars-d mailing list