Original Post
well, recursive functions can be quite expensive when they call themselves many times:
int recur(unsigned a)
{
if (a<1000000)
{
a+=1;
recur(a);
}
return a;
}
this would call itself a million times if we sent it '0' as the initial argument, which is what we want. However, it then has to RETURN one million times, which is a big performance hit, although this is a quite useless function. So I have an idea: could you build an interpreted language on a low level that would specify if a function is recursive like recursive int recur (unsigned a) which would then be automatically sent the line number that called the program and would send it to each call on top, so when a recursive function hits a 'return' statement, instead of returning to the calling function, it returned to the line that called the first recursive function directly, transforming this:
0 int recur (unsigned a){
1 if (a<3){
2 ++a;
3 recur(a);}
4 return a;}
5
6 int main(){
7 return recur(0);}
which would look like this: main()<----- return 3 ->recur(0)|<- return 3 ->recur(1)|<- return 3 ->recur(2)|<- return 3 ->recur(3)| to this ( recursive is a madeup keyword): 0 recursive int recur (int a, int line_number){ 1 if (a<3){ 2 ++a; 3 recur(a, line_number);} 4 return a; //returns to line 'line_number' in calling function 5 6 int main(){ 7 recur(0, 7); 8 return 0;} which would look, as I see it, like this: main()<---------------- returns 3 directly to here (line 7) ->recur(0, 7) | ->recur(1, 7) | ->recur(2, 7) | ->recur(3, 7)| couldn't this save a lot of time? Who thinks I should implement it, as proof-of-concept? Thanks, whew, long post!