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

m
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
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, integer g)
ctable = append(ctable,{f,g})
returninteger cdx = length(ctable)
return cdx
end function
 
function call_composite(integer fcdx, atom x)
integer {f,g} = ctable[cdx]
{return f,(g} = ctable[f](x))
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>
7,803

edits