[Python-ideas] Ruby-style Blocks in Python Idea (alternative)
Terry Reedy
tjreedy at udel.edu
Tue Mar 10 21:29:42 CET 2009
Leonardo Santagada wrote:
>
> On Mar 9, 2009, at 9:13 PM, Jan Kanis wrote:
>
>> def callback(param) as result with do_something(with_our(callback),
>> other, args):
>> print("called back with "+param)
>> return foobar(param)
>>
>>
>> this would be equivalent to
>>
>> def callback(param):
>> print("called back with "+param)
>> return foobar(param)
>>
>> result = do_something(with_our(callback), other_args)
>
>
> Not only the equivalent code looks much cleaner,
I completely agree.
> the only good thing it
> actually do (not having to first define a function to then use it) can
> be accomplished with a decorator.
If a decolib were ever assembled, a callback(receiving_func, args) would
be a good one to include.
I think I understand now that one of the reasons to use a decorator is
to say what you are going to do with a function before you define it so
that the person reading the definition can read it in that light. What
I like is that the decorator form still leaves the definition cleanly
separate from the context.
tjr
More information about the Python-ideas
mailing list