First-class functions/Use numbers analogously: Difference between revisions
First-class functions/Use numbers analogously (view source)
Revision as of 15:55, 8 March 2012
, 12 years agoAdd curried functions
(Add Axiom task) |
(Add curried functions) |
||
Line 59:
=={{header|Axiom}}==
<lang Axiom>(x,xi,y,yi) := (2.0,0.5,4.0,0.25)
(
▲multiplier(a:Float,b:Float):(Float->Float) == (m +-> a*b*m);
▲[(multiplier(number,inver)) 0.5 for number in numbers for inver in invers];
[curryLeft(*$Float,number*inver) 0.5 for number in numbers for inver in invers]▼
</lang>Output:
<lang Axiom> [0.5,0.5,0.5]
Type: List(Float)</lang>
We can also curry functions, possibly with function composition, with the same output as before:
In comparison to using functions:▼
<lang Axiom>mult(n:Float):(Float->Float) == curryLeft(*$Float,n)$MAPPKG3(Float,Float,Float)
[(mult(number)*mult(inver)) 0.5 for number in numbers for inver in invers]</lang>
▲In comparison to using first class functions alone:
<lang Axiom>fns := [sin$Float, cos$Float, (x:Float):Float +-> x^3]
inv := [asin$Float, acos$Float, (x:Float):Float +-> x^(1/3)]
Line 75 ⟶ 77:
</lang>
- which has the same output.
=={{header|C sharp|C#}}==
{{works with|C#|4.0}}
|