Anonymous recursion: Difference between revisions

m
→‎{{header|REXX}}: added whitespace, used a template for the output sections.
m (→‎{{header|REXX}}: added whitespace, used a template for the output sections.)
Line 2,416:
numeric digits 1e6 /*in case the user goes ka-razy with X.*/
parse arg x . /*obtain the optional argument from CL.*/
if x=='' | x=="," then x=12 12 /*Not specified? Then use the default.*/
w= length(x) /*W: used for formatting the output. */
do j=0 for x+1 /*use the argument as an upper limit.*/
say 'fibonacci('right(j, w)") =" fib(j)
end /*j*/ /* [↑] show Fibonacci sequence: 0 ──► X*/
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
fib: procedure; parse arg z; if z>=0 then return .(z)
say "***error*** argument can't be negative."; exit
.: procedure; parse arg #; if #<2 then return #; return .(#-1) + .(#-2)</lang>
'''{{out|output''' |text=&nbsp; when using the default input of: &nbsp; &nbsp; <tt> 12 </tt>}}
<pre>
fibonacci( 0) = 0
Line 2,449:
numeric digits 1e6 /*in case the user goes ka-razy with X.*/
parse arg x . /*obtain the optional argument from CL.*/
if x=='' | x=="," then x=12 12 /*Not specified? Then use the default.*/
@.= .; @.0= 0; @.1=1 1 /*used to implement memoization for FIB*/
w= length(x) /*W: used for formatting the output. */
do j=0 for x+1 /*use the argument as an upper limit.*/
say 'fibonacci('right(j, w)") =" fib(j)
end /*j*/ /* [↑] show Fibonacci sequence: 0 ──► X*/
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
fib: procedure expose @.; arg z; if z>=0 then return .(z)
say "***error*** argument can't be negative."; exit
.: procedure expose @.; arg #; if @.#\==. then return @.#; @.#=.(#-1)+.(#-2); return @.#</lang>
'''{{out|output''' |text=&nbsp; is the sameidentical asto the 1<sup>st</sup> REXX version.}} <br><br>
 
=={{header|Ring}}==