First-class functions/Use numbers analogously: Difference between revisions

m
→‎{{header|REXX}}: added some comments.
m (→‎{{header|REXX}}: added the REXX computer programming language for this task.)
m (→‎{{header|REXX}}: added some comments.)
Line 1,299:
<br>but the '''interpret''' instruction can be used to provide that capability.
<lang rexx>/*REXX program to use a first-class function to use numbers analogously. */
nums= 2.0 4.0 6.0 /*various numbers, can have fractions.*/
invs= 1/2.0 1/4.0 1/6.0 /*inverses of the above (real) numbers.*/
m= 0.5 /*multiplier when invoking new function*/
m= 0.5
do j=1 for words(nums); num= word(nums, j); inv= word(invs, j)
nf= multiplier(num, inv); interpret call nf m /*sets the var RESULT.*/
Line 1,308:
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
@: return left( arg(1) / 1, 15) /*format the number, left justified. */
multiplier: procedure expose n1n2; parse arg n1,n2; n1n2= n1 * n2; return 'a_new_func'
a_new_func: return n1n2 * arg(1)</lang>
Line 1,317:
number= 6 inverse= 0.166666667 m= 0.5 result= 0.5
</pre>
 
 
=={{header|Ruby}}==