[Python-ideas] Tweaking closures and lexical scoping to include the function being defined

Yuval Greenfield ubershmekel at gmail.com
Wed Sep 28 18:49:24 CEST 2011


On Sep 28, 2011 8:58 AM, "Paul Moore" <p.f.moore at gmail.com> wrote:
>
> On 28 September 2011 16:38, Guido van Rossum <guido at python.org> wrote:
> > Of course once there's different syntax, the nonlocal declaration in
> > the function is redundant. And clearly I'm back-peddling. :-)
>
> If we're back to syntax proposals on the def statement, how about
>
> def fn() with i=1, lock=Lock():
>   whatever
>
> ? This is basically another bikeshed to paint, though...
>
> Paul.
>

I also had the same idea with:

def fn() with i=1, lock=Lock():
    Whatever

So I guess it's not unobvious. Though "with" is used for something different
unless we disallow

    def fn() with NAME = EXPR:

and instead use

    def fn() with CONTEXT as NAME:

And the existing enter/exit mechanism for initialization.

Though I agree with the protesters that this construct can be an attractive
nuisance or an "anti pattern" as Greg Ewing said. Though I haven't yet been
able to articulate in which cases.

--Yuval
On Sep 28, 2011 8:58 AM, "Paul Moore" <p.f.moore at gmail.com> wrote:
> On 28 September 2011 16:38, Guido van Rossum <guido at python.org> wrote:
>> Of course once there's different syntax, the nonlocal declaration in
>> the function is redundant. And clearly I'm back-peddling. :-)
>
> If we're back to syntax proposals on the def statement, how about
>
> def fn() with i=1, lock=Lock():
> whatever
>
> ? This is basically another bikeshed to paint, though...
>
> Paul.
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20110928/0f6037da/attachment.html>


More information about the Python-ideas mailing list