On 5/17/06, Julio Oña <[EMAIL PROTECTED]> wrote:
> Just pressed replay.....

I do that all the time too :o)

> I think in python it should be something like:
>
> Having defined:
>
> def fa(value):
>     return .....
>
> def fb(value):
>     return ....
>
> def fc(value):
>      return ....
>
> function_list=[fa,fb,fc]
>
>
> Or composition function is:
>
> def compose(function_list, value)
>     return reduce(lambda fn, value: fn(value), function_list, value)

Almost. Traditionally, compose will return a function instead of
directly applying the composition. Something like:

def compose(function_list):
   return lambda value: (reduce(lambda fn, v: fn(v), function_list, value))

Actually, to make this work you would also have to reverse the
arguments to the reduce-operator, since the accumulated value will be
the first item on the list:

def compose(function_list):
   return lambda value: (reduce(lambda v, fn: fn(v), function_list, value))


> so you could call:
>
> result = compose(function_list, value)

Or if compose returns a function:
result = compose(function_list)(value)

Arnar

ps. I'm sorry for the errors in my previous posts, where I incorrectly
took compose(f,g)(x) == f(g(x)) -- the correct is compose(f,g)(x) ==
g(f(x)), i.e. the functions are applied in the same order they are
given to "compose".
For more about function composition:
http://en.wikipedia.org/wiki/Function_composition

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"MochiKit" group.
To post to this group, send email to mochikit@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/mochikit
-~----------~----~----~----~------~----~------~--~---

Reply via email to