www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Recursion Idea for functions

reply Incognito <Incognito regmail.com> writes:
I've been using recursion a lot lately and having to create 
multiple functions to deal with multiple paths can be a pain 
visually.

Instead, how bout a simpler syntax. This is just an idea, could 
be improved

void Recurse()
{
     scope(first)
     {
          `BLOCK`
     }
     scope(last)
     {
          `BLOCK`
     }

     Recurse();
}

which would be equivalent to

void Recurse2()
{
     Recurse2();
}

void Recurse()
{
     `BLOCK`
     Recurse2();
     `BLOCK`
}

doubling of functions starts to create a source mess.
Jun 13 2016
parent Steven Schveighoffer <schveiguy yahoo.com> writes:
On 6/13/16 3:21 PM, Incognito wrote:
 I've been using recursion a lot lately and having to create multiple
 functions to deal with multiple paths can be a pain visually.

 Instead, how bout a simpler syntax. This is just an idea, could be improved

 void Recurse()
 {
     scope(first)
     {
          `BLOCK`
     }
     scope(last)
     {
          `BLOCK`
     }

     Recurse();
 }

 which would be equivalent to

 void Recurse2()
 {
     Recurse2();
 }

 void Recurse()
 {
     `BLOCK`
     Recurse2();
     `BLOCK`
 }

 doubling of functions starts to create a source mess.
Why not just: void Recurse() { static void Recurse2() { Recurse2(); } `BLOCK` Recurse2() `BLOCK` } -Steve
Jun 13 2016