Jump to content

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

Added Wren
(Added Wren)
Line 1,540:
<pre>
<5.000000e-01,5.000000e-01,5.000000e-01>
</pre>
 
=={{header|Wren}}==
{{libheader|Wren-fmt}}
<lang ecmascript>import "/fmt" for Fmt
 
var multiplier = Fn.new { |n1, n2| Fn.new { |m| n1 * n2 * m } }
 
var orderedCollection = Fn.new {
var x = 2.0
var xi = 0.5
var y = 4.0
var yi = 0.25
var z = x + y
var zi = 1.0 / ( x + y )
return [[x, y, z], [xi, yi, zi]]
}
 
var oc = orderedCollection.call()
for (i in 0..2) {
var x = oc[0][i]
var y = oc[1][i]
var m = 0.5 // rather than 1 to compare with first-class functions task
Fmt.print("$0.1g * $g * $0.1g = $0.1g", x, y, m, multiplier.call(x, y).call(m))
}</lang>
 
{{out}}
Agreeing with results of first-class functions task:
<pre>
2.0 * 0.5 * 0.5 = 0.5
4.0 * 0.25 * 0.5 = 0.5
6.0 * 0.166667 * 0.5 = 0.5
</pre>
 
9,482

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.