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

no edit summary
No edit summary
Line 852:
6 * 0.16666666666667 * 0.5 = 0.5
</pre>
 
=={{header|M2000 Interpreter}}==
<lang M2000 Interpreter>
Module CheckIt {
\\ by default numbers are double
x = 2
xi = 0.5
y = 4
yi = 0.25
z = x + y
zi = 1 / ( x + y )
Composed=lambda (a, b)-> {
=lambda a,b (n)->{
=a*b*n
}
}
numbers=(x,y,z)
inverses=(xi,yi,zi)
Dim Base 0, combo(3)
combo(0)=Composed(x,xi), Composed(y,yi), Composed(z,zi)
num=each(numbers)
inv=each(inverses)
fun=each(combo())
While num, inv, fun {
Print $("0.00"), Array(num);" * ";Array(inv);" * 0.50 = "; combo(fun^)(0.5),$("")
Print
}
}
Checkit
\\ for functions we have this definition
Composed=lambda (f1, f2) -> {
=lambda f1, f2 (x)->{
=f1(f2(x))
}
}
 
</lang>
{{out}}
<pre>
2.00 * 0.50 * 0.50 = 0.50
4.00 * 0.25 * 0.50 = 0.50
6.00 * 0.17 * 0.50 = 0.50
</pre>
 
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
Anonymous user