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

Jim Jewett jimjjewett at gmail.com
Tue Mar 10 23:22:03 CET 2009

On 3/10/09, Guido van Rossum <guido at python.org> wrote:
> On Tue, Mar 10, 2009 at 1:15 PM, Terry Reedy <tjreedy at udel.edu> wrote:
>>> On Mon, Mar 9, 2009 at 4:09 PM, Terry Reedy <tjreedy at udel.edu> wrote:

>>>> ... What I dislike is the anonymity-cult claim that the defect is a virtue.

>> The convenience is from having function expressions.  If the expression
>> syntax allowed the optional attachment of a name, it would be just as
>> convenient.  In some cases, I am sure people would find it even more
>> convenient if they could add in a name, especially when there is nothing
>> else in the structure to serve as a substitute.

>> 'Anonymous' is a different concept from 'expression-defined' despite the
>> tendency to conflate the two.

> If I read you correctly you're saying that having an expression that
> returns a function (other than referencing it by name) is not the same
> as having anonymous functions. This sounds like quite the
> hairsplitting argument. Why is it important to you to split this
> particular hair?

An expression that *creates* and returns a function is useful.

A way to create unnamed functions may or may not be useful.

Right now, the two are tied together, as lambda is the best way to do
either.  Mentally untangling them might lead to better code.

If the name in a def were optional, it would meet the perceived need
for anonymity, but still wouldn't meet the need for creating and
returning a function within a single expression.

    # Would this really ever be useful?
    # Not to me, but the anon-lovers suggest yes.
    # Cognition difference, or just confounding the two uses of lambda?
    def (a): return a+3

On the other hand, if def became an expression, it would meet the need
for function-creating expressions (and would have at least reduced the
need for decorators).

    add_callback(button1, def add3(a): return a+3)

(And yes, I understand that there are reasons why class, def, and
import do not return values, even if I sometimes wish they did.)


More information about the Python-ideas mailing list