Talk:Find limit of recursion

From Rosetta Code
Revision as of 09:02, 24 August 2010 by rosettacode>Axtens (Hmm ... I wonder)

I suspect that the recursion limit depends often on the compiler (for compiled languages), operating system (stack assigned to a process could be tuned, I suppose, and may change from O.S. to O.S.), implementation of an "interpreter" (when more than one exists) and/or on how the recursive function/method/whatever is written. E.g. C version passes an argument to keep track of the depth, Sather uses a class attribute ... Different ways change the limit (it's not the case of the C version in my tests since clearly gcc optimizes using a register to pass the only argument) ...

Current GNU Sather compiler uses C as intermediate language; so the more limited recursion depth could depends on the fact that sather's "functions" translated in C have to keep something like a "context", being part of a class (more real arguments), or/and simply they use more stack because of needed variables that appear in the translated code... in fact it looks this way:

<lang c>void MAIN_recurse(MAIN self) {

INT L1;
INT L21_;
OUT L3;
dSTR L4;
OB L5;
OUT L6;
extern STR name6;
L1 = ATTR(self,r);
L21_=INTPLUS(L1,1); 
SATTR(self,r,L21_);
L3 = OUT_createrOUT(((OUT) NULL));
L5=ZALLOC_LEAF(sizeof(struct INT_boxed_struct));
if (L5==NULL) FATAL("Unable to allocate more memory");
memset(L5,0,sizeof(struct INT_boxed_struct));
((OB)L5)->header.tag=INT_tag;
L4 = (dSTR)((INT_boxed) L5);
((INT_boxed) L4)->immutable_part = ATTR(self,r);
L6 = OUT_pl930378279(L3, L4);
OUT_plus_STR(L6, ((STR) &name6));
MAIN_recurse(self);

}</lang>

The point is... depending the recursion max depth on too many parameters, shouldn't we specify the environment (O.S., compiler, interpreter) running the examples? Otherwise a novice user could think that the shown limit is hardcoded somewhere in the nature of the language (that could be, maybe, for some languages, and should be noted!) —ShinTakezou 14:46, 20 April 2010 (UTC)

The name of the game

Noticed now... the name is Find Limit of Recursion, while I've read proposal for naming like "Find limit of recursion"... I suppose this page should be moved (I think slowly and act too fastly, thus let someone else do it properly)... —ShinTakezou 15:11, 20 April 2010 (UTC)

Done --Mwn3d 15:26, 20 April 2010 (UTC)

Rules

What if language normally compiles tail-recursion to not use stack at all? Do we need to force non tail recursivity or need to say that there is no limit?

If your code does not find the limit, that would be a bug in your code. But tail recursion issues are certainly worth documenting. A related [but different] issue has to do with stack frame sizes. --Rdm 01:39, 24 May 2010 (UTC)


Hmm ... I wonder

Regarding the COBOL example, I haven't found out yet how to 'catch' the error during a run. Is it possible?