[Python-ideas] Ruby-style Blocks in Python Idea
bruce at leapyear.org
Wed Mar 11 19:06:55 CET 2009
(1) I can easily write an expression that returns a function of arbitrary
(2) What I can't easily write is an expression that is arbitrarily complex
and returns a function with that complexity.
Sorry if that's unclear. My point is that if I know what the complexity is
in advance I can write it down. If I can't, do I really want to embed this
in the middle of some other function?
>>> def f(name, x):
def _(i, x=x):
// do complicated stuff
_.__name__ = name
Then f('bar', 3) returns a function equivalent to lambda i: i+3, etc. and of
course the definition of f can be arbitrarily complicated although that
complexity must be planned in advance. I can stick f('bar', 3) anywhere I
want a function.
What I have yet to hear is an explanation of the advantages of providing (2)
since we already have (1) and lambda.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas