Re: RosettaCode
- Posted by PeteE Jan 26, 2011
- 1940 views
mattlewis said...
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
Still, this doesn't seem to be in the spirit of function composition. This compose function returns a "compose-id" which isn't compatible with routine-ids. With this you can't further compose two composed functions, although you've helpfully allowed any number of functions to be composed which should be equivalent. You still can't use a compose-id with anything expecting a routine-id.