[Python-ideas] Ruby-style Blocks in Python Idea

Bruce Leban 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
complexity.
(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?

For example:

>>> def f(name, x):
    def _(i, x=x):
        // do complicated stuff
        return i+x
    _.__name__ = name
    return _

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.

--- Bruce
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20090311/0444ef90/attachment.html>


More information about the Python-ideas mailing list