[Python-ideas] Ruby-style Blocks in Python Idea (alternative)
Jan Kanis
jan.kanis at phil.uu.nl
Thu Mar 12 00:08:38 CET 2009
On Wed, Mar 11, 2009 at 21:32, Joel Bender <jjb5 at cornell.edu> wrote:
> Jan Kanis wrote:
>
>> @lambda f: do_something(with_our(f))
>> def result(param):
>> print("called back with "+param)
>> return foobar(param)
>
> To keep result from stomping on the name, I would expect result to actually
> be a result rather than a function :-):
'result' is the actual result. To try it out in current python:
def do_something(func):
print("doing something")
return func(41)**2
def id(x):
return x
@id(lambda f: do_something(f))
def result(param):
print("called back with", param)
return param + 1
print("result is", result, "should be", 42**2)
-->
doing something
called back with 41
result is 1764 should be 1764
Or did I misinterpret what you were saying?
More information about the Python-ideas
mailing list