Re: Calling nested function before declaration

2018-09-27 Thread nkm1 via Digitalmars-d
On Wednesday, 26 September 2018 at 22:46:21 UTC, Jonathan wrote: This code fails to compile: ("undefined identifier fun") void main() { fun(); void fun() {} } Having the call after the declaration works: void main() { void fun() {} fun(); } Is this how it is intended to work? I

Re: Calling nested function before declaration

2018-09-27 Thread Walter Bright via Digitalmars-d
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 ne

Re: Calling nested function before declaration

2018-09-27 Thread Timon Gehr via Digitalmars-d
On 27.09.2018 00:46, Jonathan wrote: I can't see how the current behavior is at all better or to be preferred unless it is faster to compile?  What is the reason for it being how it is? The current behavior is easy to specify and simple to implement, and it is what Walter has implemented. A

Re: Calling nested function before declaration

2018-09-27 Thread Timon Gehr via Digitalmars-d
On 27.09.2018 01:05, Neia Neutuladh wrote: The standard ways of dealing with this: * Reorder the declarations. * Make the functions non-nested. * Get rid of mutual recursion. * Use a delegate. * Do a method-to-method-object refactoring. * turn the function with the forward reference into a te

Re: Calling nested function before declaration

2018-09-26 Thread Neia Neutuladh via Digitalmars-d
On 09/26/2018 03:46 PM, Jonathan wrote: I can't see how the current behavior is at all better or to be preferred unless it is faster to compile?  What is the reason for it being how it is? void outerFunction() { func(); auto lock = acquireLock(); void nested() { } } Inside `nested`,

Calling nested function before declaration

2018-09-26 Thread Jonathan via Digitalmars-d
This code fails to compile: ("undefined identifier fun") void main() { fun(); void fun() {} } Having the call after the declaration works: void main() { void fun() {} fun(); } Is this how it is intended to work? It seems goofy that this works: void main() { void fun2() {}