First-class functions: Difference between revisions
→{{header|Phix}}
(Added SuperCollider example) |
|||
Line 1,820:
40
126</pre>
=={{header|Phix}}==
There is not really any direct support for this sort of thing in Phix, but it is all pretty trivial to manage explicitly:
<lang Phix>sequence ctable = {}
function compose(integer f, integer g)
ctable = append(ctable,{f,g})
return length(ctable)
end function
function call_composite(integer f, atom x)
integer g
{f,g} = ctable[f]
return call_func(f,{call_func(g,{x})})
end function
function plus1(atom x)
return x+1
end function
function halve(atom x)
return x/2
end function
constant m = compose(routine_id("halve"),routine_id("plus1"))
?call_composite(m,1) -- displays 1
?call_composite(m,4) -- displays 2.5</lang>
=={{header|PHP}}==
|