[Python-ideas] Ruby-style Blocks in Python Idea
Guido van Rossum
guido at python.org
Tue Mar 10 23:27:28 CET 2009
On Tue, Mar 10, 2009 at 3:22 PM, Jim Jewett <jimjjewett at gmail.com> wrote:
> 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.
I'm feeling really dense right now -- I still don't see the difference
between the two. Are you saying that you would prefer an expression
that creates a *named* function? That seems to be really bizarre --
like claiming that you don't like expressions that return anonymous
> 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.
Moreover, unless you used a decorator, there would be no way to do
anything with the anonymous function, so it would be useless.
> # 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).
I don't see the conceptual difference between a "def-expression" (if
it were syntactically possible) and a lambda-expression. What is the
difference in your view? Are you sure that difference exists? (It
wouldn't be the first time that people ascribe powers to lambda that
it doesn't have. :-)
> add_callback(button1, def add3(a): return a+3)
Two questions about this example: (1) Do you expect the name 'add3' to
be bound in the surrounding scope? (2) What is the purpose of the name
other than documenting the obvious?
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-ideas