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

Line 911:
0.5</pre>
The structure of this is identical to first-class function task.
 
=={{header|Phix}}==
<lang Phix>sequence mtable = {}
 
function multiplier(atom n1, atom n2)
mtable = append(mtable,{n1,n2})
return length(mtable)
end function
 
function call_multiplier(integer f, atom m)
atom {n1,n2} = mtable[f]
return n1*n2*m
end function
 
constant x = 2,
xi = 0.5,
y = 4,
yi = 0.25,
z = x + y,
zi = 1 / ( x + y )
 
integer m = multiplier(routine_id("halve"),routine_id("plus1"))
 
?call_multiplier(multiplier(x,xi),0.5)
?call_multiplier(multiplier(y,yi),0.5)
?call_multiplier(multiplier(z,zi),0.5)</lang>
{{out}}
<pre>
0.5
0.5
0.5
</pre>
I should perhaps note that output in Phix automatically rounds to the specified precision (10 d.p. if none) so 4.9999 to two decimal places is shown as 5.00, and you can be pretty sure that sort of is happening on the last line.
 
=={{header|PicoLisp}}==
7,818

edits