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

Add 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)
Showing the example using both a multipler function and currying:
<lang Axiom>(xz,xi,y,yizi) := (2.0x+y,0.5,4.0,0.251/(x+y));
(znumbers,ziinvers) := ([x+y,1/(x+y,z],[xi,yi,zi]));
multiplier(a:Float,b:Float):(Float->Float) == (m +-> a*b*m);
(numbers,invers) := ([x,y,z],[xi,yi,zi]);
[(multiplier(number,inver)) 0.5 for number in numbers for inver in invers];
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)
[curryLeftmult(*$Float,number*inver) 0.5 for number in numbers for inver in invers]
[(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}}
136

edits