Multi-line lambda proposal.

Sybren Stuvel sybrenUSE at
Thu May 11 11:53:08 CEST 2006

yairchu at enlightened us with:
> this is how I think it should be done with multi-line lambdas:
> def arg_range(inf, sup, f):
>   return lambda(arg):
>     if inf <= arg <= sup:
>       return f(arg)
>     else:
>       raise ValueError

This is going to be fun to debug if anything goes wrong. Ever seen
such a traceback?

> and instead of
> @arg_range(5, 17)
> def f(arg):
>   return arg*2
> you do:
> f = arg_range(5, 17, lambda(arg)):
>   return arg*2

A function decorator is supposed to add something to a function. The
syntax that sticks the closest to that of defining a function seems
most Pythonic to me.

I can already foresee that I'll have a tougher time explaining your
lambda-based "decorators", than the current decorators, to people
learning Python.

The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
                                             Frank Zappa

More information about the Python-list mailing list