[Python-Dev] Anonymous blocks: Thunks or iterators?

Guido van Rossum gvanrossum at gmail.com
Fri Apr 29 19:55:28 CEST 2005


[Michael Hudson]
> I think the making-generators-more-sexy thing is nice, but I'm think
> that's almost orthogonal.

Not entirely. I agree that "continue EXPR" calling next(EXPR) which
enables yield-expressions is entirely orthogonal.

But there are already two PEPs asking for passing exceptions and/or
cleanup into generators and from there it's only a small step to using
them as resource allocation/release templates. The "small step" part
is important -- given that we're going to do that work on generators
anyway, I expect the changes to the compiler and VM to support the
block statement are actually *less* than the changes needed to support
thunks.

No language feature is designed in isolation.

> Did you read this mail:
> 
> http://mail.python.org/pipermail/python-dev/2005-April/052970.html
> 
> ? In this proposal, you have to go to some effort to make the thunk
> survive the block, and I think if weirdness results, that's the
> programmer's problem.

It's not a complete proposal though. You say "And grudgingly, I guess 
you'd need to make returns behave like that anyway" (meaning they
should return from the containing function). But you don't give a hint
on how that could be made to happen, and I expect that by the time
you've figured out a mechanism, thunks aren't all that simple any
more.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-Dev mailing list