Anonymous recursion: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: added comments, added subroutine fence, added DO-END comment label, changed comments, added whitespace. -- ~~~~)
Line 1,129: Line 1,129:
to be OK with implementors, here is the REXX version:
to be OK with implementors, here is the REXX version:
<lang rexx>/*REXX program to show anonymous recursion (of a function/subroutine). */
<lang rexx>/*REXX program to show anonymous recursion (of a function/subroutine). */

numeric digits 1e6 /*in case the user goes kaa-razy.*/
numeric digits 1e6 /*in case the user goes kaa-razy.*/


do j=0 to word(arg(1) 12,1) /*use argument or the default: 12*/
do j=0 to word(arg(1) 12, 1) /*use argument or the default: 12*/
say 'fibonacci('j") =" fib(j) /*show Fibonacci sequence: 0──>x */
say 'fibonacci('j") =" fib(j) /*show Fibonacci sequence: 0──►x */
end /*j*/
end /*j*/
exit /*stick a fork in it, we're done.*/
exit
/*──────────────────────────────────subroutines─────────────────────────*/

fib: procedure; if arg(1)>=0 then return .(arg(1))
/*-----------------------------------FIB subroutine---------------------*/
say "***error!*** argument can't be negative."; exit
fib: procedure; if arg(1)>=0 then return .(arg(1))
.:procedure; arg _; if _<2 then return _; return .(_-1)+.(_-2)</lang>
say "***error!*** argument can't be negative."; exit

.:procedure; arg _; if _<2 then return _; return .(_-1)+.(_-2)</lang>
'''output''' when using the default input (<tt> 12 </tt>):
'''output''' when using the default input (<tt> 12 </tt>):
<pre style="overflow:scroll">
<pre style="overflow:scroll">