Jump to content

Higher-order functions: Difference between revisions

→‎{{header|REXX}}: added the REXX language. -- ~~~~
No edit summary
(→‎{{header|REXX}}: added the REXX language. -- ~~~~)
Line 1,469:
31 [ ( n-n ) 100 * ] disp
</lang>
 
=={{header|REXX}}==
<lang rexx>
/*pass a function as a name to a function. */
 
n=3735928559
funcName='fib' ; q= 10; call someFunction funcName,q; call tell
funcName='fact' ; q= 6; call someFunction funcName,q; call tell
funcName='square' ; q= 13; call someFunction funcName,q; call tell
funcName='cube' ; q= 3; call someFunction funcName,q; call tell
funcName='reverse'; q=721; call someFunction funcName,q; call tell
say '~~~~~~~~~'
say 'done as' d2x(n)"." /*prove that var N still intact.*/
exit
 
 
/*──────────────────────────────────────where the rubber meets the road.*/
someFunction: procedure; arg whatwhat,n; signal value (whatwhat)
say result 'result'
return
 
/*──────────────────────────────────────functions that are on the road. */
cube: return n**3
square: return n**2
reverse: return 'REVERSE'(n)
fact: !=1; do j=2 to n; !=!*j; end; return !
tell: say right(funcName'('q") = ",20)result; return
fib: if n==0 then return n; if n==1 then return n;_=0; a=0; b=1
do j=2 to n; _=a+b; a=b; b=_; end; return _
</lang>
Output:
<pre style="height:25ex;overflow:scroll">
fib(10) = 55
fact(6) = 720
square(13) = 169
cube(3) = 27
reverse(721) = 127
~~~~~~~~~
done as DEADBEEF.
</pre>
 
=={{header|Ruby}}==
Cookies help us deliver our services. By using our services, you agree to our use of cookies.