First-class functions/Use numbers analogously: Difference between revisions
Content added Content deleted
(Add Axiom task) |
|||
Line 58: | Line 58: | ||
</pre> |
</pre> |
||
=={{header|Axiom}}== |
|||
Showing the example using both a multipler function and currying: |
|||
<lang Axiom>(x,xi,y,yi) := (2.0,0.5,4.0,0.25); |
|||
(z,zi) := (x+y,1/(x+y)); |
|||
(numbers,invers) := ([x,y,z],[xi,yi,zi]); |
|||
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> |
|||
In comparison to using functions: |
|||
<lang Axiom>fns := [sin$Float, cos$Float, (x:Float):Float +-> x^3] |
|||
inv := [asin$Float, acos$Float, (x:Float):Float +-> x^(1/3)] |
|||
[(f*g) 0.5 for f in fns for g in inv] |
|||
</lang> |
|||
- which has the same output. |
|||
=={{header|C sharp|C#}}== |
=={{header|C sharp|C#}}== |
||
{{works with|C#|4.0}} |
{{works with|C#|4.0}} |