[Python-ideas] Allow lambda decorators

Chris Rebert pyideas at rebertia.com
Mon Feb 9 11:33:15 CET 2009


On Mon, Feb 9, 2009 at 2:21 AM, Marcin 'Qrczak' Kowalczyk
<qrczak at knm.org.pl> wrote:
> On Mon, Feb 9, 2009 at 07:02, Chris Rebert <pyideas at rebertia.com> wrote:
>
>> The basic idea was (using the keyword "bind" for the sake of argument):
>>
>> def func_maker():
>>    fs = []
>>    for i in range(10):
>>        def f():
>>            bind i #this declaration tells Python to grab the value of
>> i as it is *right now* at definition-time
>>            return i
>>        fs.append(f)
>>    return fs
>
> When is "now"? The bind, whatever it does, is not executed until the
> function is called, which is too late. Letting it influence the
> interpretation of f itself is confusing.

Well, it's a declaration of sorts, so it would hypothetically be taken
into account at definition-time rather than call-time (that's it's
entire raison detre!); surely we can agree that 'global' can also be
viewed as having definition-time rather than call-time effects? It is
somewhat confusing, but then so is the problem it's trying to solve
(the unintuitive behavior of functions defined in a loop).

But yes, I agree the idea has been thoroughly thrashed (as I
predicted) and at least now the discussion is preserved for posterity
should similar ideas ever resurface. :)

Cheers,
Chris

--
Follow the path of the Iguana...
http://rebertia.com



More information about the Python-ideas mailing list