Re: RosettaCode
- Posted by mattlewis (admin) Jan 26, 2011
- 2000 views
PeteE said...
mattlewis said...
bruce1961 said...
Nice to see some folk have taken up the challenge.
Is it fair enough to assume that Function Composition is impossible in Euphoria?
No, you can do it using routine_ids:
function compose( integer f, integer g, object x ) return call_func( f, {call_func( g, {x} )} ) end function
Matt
That isn't really function composition though. The compose function should only take arguments f and g, and return a routine_id, not a value.
Yeah, I suppose not. With a little more work:
sequence compositions = {} function compose( sequence ids ) compositions = append( compositions, ids ) return length( compositions ) end function function call_composition( integer c, sequence x ) sequence comp = compositions[c] for i = length( comp ) to 1 by -1 do x = call_func( comp[i], x ) end for return x end function ... fg = compose( f, g ) call_composition( fg, {1} )
Matt