[Python-ideas] Anonymous blocks (again):
Devin Jeanpierre
jeanpierreda at gmail.com
Sun May 12 10:18:55 CEST 2013
On Sun, May 12, 2013 at 2:11 AM, Juancarlo Añez <apalala at gmail.com> wrote:
> On Sun, May 12, 2013 at 12:45 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:
>>
>> In current Python, decorator abuse can be a reasonable option:
>>
>> @closure
>> def block():
>> self.rule()
>> self.ast['rules'] = self.last_node
>
>
> Buf for that to work, you'd still have to call:
>
> block()
>
> And that would make it:
>
> @closure
> def block():
> self.rule()
> self.ast['rules'] = self.last_node
> block()
No, not with how closure was defined in the original post. (Otherwise,
the code would be closure(block)()).
Consider:
>>> def closure(f):
... f(); f(); f()
...
>>> @closure
... def block():
... print "Hi"
...
Hi
Hi
Hi
-- Devin
More information about the Python-ideas
mailing list