Anonymous user
First-class functions/Use numbers analogously: Difference between revisions
First-class functions/Use numbers analogously (view source)
Revision as of 21:21, 15 December 2020
, 3 years ago→{{header|Nim}}
Line 998:
6.00 * 0.17 * 1.00 = 1.00
</pre>
=={{header|Nim}}==
<lang Nim>
func multiplier(a, b: float): auto =
let ab = a * b
result = func(c: float): float = ab * c
let
x = 2.0
xi = 0.5
y = 4.0
yi = 0.25
z = x + y
zi = 1.0 / ( x + y )
let list = [x, y, z]
let invlist = [xi, yi, zi]
for i in 0..list.high:
# Create a multiplier function...
let f = multiplier(list[i], invlist[i])
# ... and apply it.
echo f(0.5)</lang>
{{out}}
<pre>0.5
0.5
0.5</pre>
=={{header|Objeck}}==
|