First-class functions/Use numbers analogously: Difference between revisions
Content added Content deleted
(Added Ada (and Removed {{omit From|Ada}})) |
(→{{header|Mathematica}}: Fixed issue with code not being comparable to first-class functions) |
||
Line 564:
=={{header|Mathematica}}==
This code demonstrates the example using structure similar to function composition, however the composition function is replace with the multiplier function.
<lang Mathematica>f[x_, y_] := x*y*# &▼
<lang Mathematica>multiplier[n1_,n2_]:=n1 n2 #&
num={2,4,2+4};
numi=1/num;
multiplierfuncs = multiplier @@@ Transpose[{num, numi}];
</lang>
The resulting functions are unity multipliers:
<pre>Table[i[0.666], {i, multiplierfuncs}]
{0.666, 0.666, 0.666}</pre>
Note that unlike Composition, the above definition of multiplier only allows for exactly two arguments. The definition can be changed to allow any nonzero number of arguments:
</lang>
=={{header|Nemerle}}==
|