[Python-Dev] thunks (original) (raw)

Guido van Rossum guido@python.org
Mon, 03 Feb 2003 11:53:50 -0500


I still don't have time to read this thread :-(, but I had a new idea that I'd like to fly here.

If we want to support thunks that blend into the scope of their environment as well as thunks that introduce a new local scope, here's one possible way to do it:

Thunk blending in:

[ =] :

Thunk introducing a new local scope:

[ =] lambda:

(Never mind the ugly things I've said about lambda in the past. :-)

I'm confident that the parser can distinguish these, and I'm confident that the scope blending can be implemented using nested-scope cells.

Adding formal parameters to the second case would go like this:

[ =] lambda :

One concern I have in both cases: I think there are use cases for wanting more than one block. Glyph's example wants to define various callbacks for a remote call, and this would need multiple blocks. I think the syntax for this would have to use some kind of keyword-based continuation, e.g.

[ =] lambda: and lambda: ...

Disclaimer: this is a half-baked idea.

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