Find limit of recursion: Difference between revisions

added RPL
(Added Gambas)
(added RPL)
 
(One intermediate revision by one other user not shown)
Line 2,661:
 
Obviously, if the procedure '''recursive''' would have contained local variables, the depth of recursion would be reached much earlier...
 
=={{header|PL/M}}==
<syntaxhighlight lang="PL/M">
100H:
BDOS: PROCEDURE (FN, ARG); DECLARE FN BYTE, ARG ADDRESS; GO TO 5; END BDOS;
EXIT: PROCEDURE; CALL BDOS(0,0); END EXIT;
PRINT: PROCEDURE (S); DECLARE S ADDRESS; CALL BDOS(9,S); END PRINT;
PRINT$NUM: PROCEDURE (N);
DECLARE S (8) BYTE INITIAL ('.....',13,10,'$');
DECLARE (N, P) ADDRESS, C BASED P BYTE;
P = .S(5);
DIGIT:
P = P-1;
C = N MOD 10 + '0';
IF (N := N/10) > 0 THEN GO TO DIGIT;
CALL PRINT(P);
END PRINT$NUM;
 
RECURSE: PROCEDURE;
DECLARE CNT ADDRESS INITIAL (1);
 
CALL PRINT$NUM(CNT);
CNT = CNT + 1;
CALL RECURSE;
 
END RECURSE;
 
CALL RECURSE;
CALL EXIT;
 
EOF
</syntaxhighlight>
 
=={{header|PowerShell}}==
Line 2,962 ⟶ 2,994:
recurse(x+1)
</syntaxhighlight>
 
=={{header|RPL}}==
« 1 + <span style="color:blue">RECUR</span> » '<span style="color:blue">RECUR</span>' STO
 
0 <span style="color:blue">RECUR</span>
Each recursive call will increase the return stack size by 5 nibbles, which means that on a basic 32-kilobyte calculator, there's room for over 10,000 recursive calls of the above type. If the recursion algorithm needs to pass arguments through the data stack or use local variables, the number of recursions will be much lower.
 
=={{header|Ruby}}==
1,150

edits