www.digitalmars.com         C & C++   DMDScript  

D - Recursive function literals?

reply James Widman <james jwidman.com> writes:
Is there any way to do it? If not, then I'm thinking, since "body" is 
already a keyword, you could just use that: 

h(function int ( int i ) { if ( i == 0 ) return i; 
return i + body( i-1); 
   });

If that becomes adopted, it might also be good to encourage the use of 
"body" for recursions in general; it's like a big red flag that says "I 
recurse!", which could be handy in functions so large that you 
temporarily forget their names while reading them. ;-)
Apr 22 2004
next sibling parent "Walter" <walter digitalmars.com> writes:
I think it would be better to just name it!

"James Widman" <james jwidman.com> wrote in message
news:james-CD365A.13185322042004 digitalmars.com...
 Is there any way to do it? If not, then I'm thinking, since "body" is
 already a keyword, you could just use that:

 h(function int ( int i ) { if ( i == 0 ) return i;
 return i + body( i-1);
    });

 If that becomes adopted, it might also be good to encourage the use of
 "body" for recursions in general; it's like a big red flag that says "I
 recurse!", which could be handy in functions so large that you
 temporarily forget their names while reading them. ;-)

Apr 22 2004
prev sibling parent "C. Sauls" <ibisbasenji yahoo.com> writes:
I'm strange, but I like it.  Then again I'm also of the opinion that 
there ought to be a 'pass()' statement for recursing into the 
superclass.  A la:

class Foo {
   int somefunc(int x) { ... }
}

class Bar {
   override int somefunc(int x) {
     if (x == SOME_SPECIAL_CASE)
       // ... do stuff
     pass(x); // used to be: super.somefunc(x)
   }
}

I think pass() and body() would make nice siblings.

-C. Sauls
-Invironz

James Widman wrote:
 Is there any way to do it? If not, then I'm thinking, since "body" is 
 already a keyword, you could just use that: 
 
 h(function int ( int i ) { if ( i == 0 ) return i; 
 return i + body( i-1); 
    });
 
 If that becomes adopted, it might also be good to encourage the use of 
 "body" for recursions in general; it's like a big red flag that says "I 
 recurse!", which could be handy in functions so large that you 
 temporarily forget their names while reading them. ;-)

Apr 22 2004