Multi-line lambda proposal.
Antoon Pardon
apardon at forel.vub.ac.be
Wed May 10 04:54:17 EDT 2006
Op 2006-05-10, yairchu at gmail.com schreef <yairchu at gmail.com>:
> multi-line lambdas, had it been added to python a long time ago, would
> had reduced a lot of complexity in the language.
> for example - with multi-line lambdas - decorators are unneccesary.
I don't like the words neccesary or unneccesary in these discussions,
because they rarely add anything. For instances decorators are
unneccesary in python now, even without multi-line lambdas.
There is nothing you can do with decorators that you can't do
without.
> just give the multi-line lambda as an argument to a function - no need
> for special syntax..
There is no need for special syntax. The decorators are just syntactic
sugar to do something that was already possible before.
> the alternative decorators would also be simpler.
> currently when you want to create a "decorator-that-accepts-additional-
> arguments" you gotta make a funtion that gets those
> additional-arguments and returns a function that will be the decorator.
Could you give me an example. Suppose I have the following:
def arg_range(inf, sup):
def check(f):
def call(arg):
if inf <= arg <= sup:
return f(arg)
else:
raise ValueError
return call
return check
@arg_range(3, 12)
def func(arg):
return arg
How would this look simpler with multi-line lambda's?
--
Antoon Pardon
More information about the Python-list
mailing list