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

Andrew McGregor andrew@indranet.co.nz
Tue, 04 Feb 2003 13:03:34 +1300


--==========1968576916========== Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline

--On Monday, February 03, 2003 11:53:50 -0500 Guido van Rossum=20 <guido@python.org> wrote:

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: [ =3D] : Thunk introducing a new local scope: [ =3D] 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: [ =3D] lambda :

+1 on all these :-)

Great stuff.

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.

[ =3D] lambda: and lambda: ... Disclaimer: this is a half-baked idea. --Guido van Rossum (home page: http://www.python.org/~guido/)

What about:

with: n1 =3D x1 lambda: n2 =3D x2 lambda: do expression

as a way to pass keyword arguments to expression? That would do it. The=20 only issue would then be passing multiple blocks with the same name, a la=20 try: except: except:, but I don't think that's to bad a thing to lose.

Andrew --==========1968576916========== Content-Type: application/pgp-signature Content-Transfer-Encoding: 7bit

-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE+PwNWHamGxvX4LwIRAvC2AJ9JU/lfC3JvrWz3xO5OagByj+5MHACfXusZ IgFRlgFgNdf6x3VSWmDUvMM= =+nwk -----END PGP SIGNATURE-----

--==========1968576916==========--