First-class functions/Use numbers analogously: Difference between revisions
First-class functions/Use numbers analogously (view source)
Revision as of 15:33, 16 April 2020
, 4 years ago→{{header|Phix}}: tidy
Thundergnat (talk | contribs) (Rename Perl 6 -> Raku, alphabetize, minor clean-up) |
m (→{{header|Phix}}: tidy) |
||
Line 1,163:
Compared to first class functions, there are (as in my view there should be) significant differences in the treatment of numbers and functions, but as mentioned on that page tagging ctable entries should be quite sufficient.
<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>
|