[Issue 7459] New: working around nested function declaration order

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Feb 7 11:04:31 PST 2012


http://d.puremagic.com/issues/show_bug.cgi?id=7459

           Summary: working around nested function declaration order
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: spec
          Severity: enhancement
          Priority: P2
         Component: websites
        AssignedTo: nobody at puremagic.com
        ReportedBy: timon.gehr at gmx.ch


--- Comment #0 from timon.gehr at gmx.ch 2012-02-07 11:04:28 PST ---
d-programming-language.org/function sez:

Unlike module level declarations, declarations within function scope are
processed in order. This means that two nested functions cannot mutually call
each other:

void test() {
  void foo() { bar(); } // error, bar not defined
  void bar() { foo(); } // ok
}

The solution is to use a delegate:

void test() {
  void delegate() fp;
  void foo() { fp(); }
  void bar() { foo(); }
  fp = &bar;
}

The proposed solution is unnecessarily complicated and non-optimal. Since
nested template functions are instantiated with the state of the symbol table
of the lexically first instantiation, this is a superior solution:

void test() {
    void foo()() { bar(); } // ok
    void bar()   { foo(); } // ok
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list