Find limit of recursion: Difference between revisions

Content added Content deleted
(→‎{{header|REXX}}: added another version of the recursive subroutine. -- ~~~~)
Line 1,177: Line 1,177:


=={{header|REXX}}==
=={{header|REXX}}==
===recursive procedure===
On (IBM's) VM/CMS, the limit of recursion was built-into CMS to stop run-away REXX programs calling recursively, it was either 200 or 250 as I recall.
On (IBM's) VM/CMS, the limit of recursion was built-into CMS to stop run-away REXX programs calling recursively, it was either 200 or 250 as I recall.
<br>This limit was maybe changed later to allow the user to specify the limit. My memory is really fuzzy about these details.
<br>This limit was maybe changed later to allow the user to specify the limit. My memory is really fuzzy about these details.
<lang rexx>/*REXX program tests the limit of recursion. */
<lang rexx>/*REXX pgm finds the recursion limit: a subroutine that calls itself. */
parse version x; say x; say
n=0
n=0
call self
call SELF 1
exit /*this statement will never be executed.*/
exit /*this statement will never be executed.*/
/*───────────────────────────SELF procedure─────────────────────────────*/

self: procedure expose n
self: procedure expose n
n=n+1
n=n+1
if n//100==0 then say n
say n
call self</lang>
call self</lang>
'''output''' using Regina 3.5 under Windows/XP Pro
'''output''' using Regina 3.6 under Windows/XP Pro
<pre style="overflow:scroll">
<pre style="overflow:scroll">
REXX-Regina_3.6(MT) 5.00 31 Dec 2011
.
.
.
.
Line 1,206: Line 1,209:
<br>The recursion level wasn't captured, but the last number shown was 240.
<br>The recursion level wasn't captured, but the last number shown was 240.
<pre style="overflow:scroll">
<pre style="overflow:scroll">
REXX/Personal 4.00 21 Mar 1992
.
.
.
.
.
.
12 +++ call self
10 +++ call self
12 +++ call self
10 +++ call self
12 +++ call self
10 +++ call self
12 +++ call self
10 +++ call self
12 +++ call self
10 +++ call self
12 +++ call self
10 +++ call self
12 +++ call self
10 +++ call self
12 +++ call self
10 +++ call self
12 +++ call self
10 +++ call self
4 +++ call self
4 +++ call SELF 1
Error 5 on line 12 of D:\SELF.REX: Machine resources exhausted
Error 5 on line 10 of D:\SELF.REX: Machine resources exhausted
</pre>
</pre>
'''output''' using R4 REXX under Windows/XP Pro
'''output''' using R4 REXX under Windows/XP Pro
<pre style="overflow:scroll">
<pre style="overflow:scroll">
REXX-r4 4.00 29 Apr 2012
.
.
.
.
Line 1,239: Line 1,244:
<pre>
<pre>
See Category ooRexx for its behavior for this program.
See Category ooRexx for its behavior for this program.
</pre>

===resurive subroutine===
<lang rexx>/*REXX pgm finds the recursion limit: a subroutine that calls itself. */
parse version x; say x; say
n=0
call SELF 2
exit /*this statement will never be executed.*/
/*───────────────────────────SELF subroutine────────────────────────────*/
self: n=n+1
say n
call self</lang>
'''output'''
<pre>
For Regina 3.6, it was 828,441.
For Personnal REXX, it was 240 (the same).
For R4, it was 507.
</pre>
</pre>