First-class functions: Difference between revisions
m
→{{header|Phix}}: tidied up
Thundergnat (talk | contribs) (Rename Perl 6 -> Raku, alphabetize, minor clean-up) |
m (→{{header|Phix}}: tidied up) |
||
Line 2,145:
=={{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.<br>
In the following, as it stands, constant m cannot be used the same way as a routine_id, and a standard routine_id cannot be passed to he first argument of call_composite, but tagging ctable entries so that you know exactly what to do with them does not sound difficult to me.
<lang Phix>sequence ctable = {}
function compose(integer f,
ctable = append(ctable,{f,g})
return cdx
end function
function call_composite(integer
integer {f,g} = ctable[cdx]
end function
function plus1(atom x)
return x+1
end function
function halve(atom x)
return x/2
end function
constant m = compose(
?call_composite(m,1) -- displays 1
?call_composite(m,4) -- displays 2.5</lang>
|