[Python-Dev] Re: Extended Function syntax

Guido van Rossum guido@python.org
Sat, 01 Feb 2003 15:08:55 -0500


I received this from Glyph.  He brings up some interesting use cases
for thunks.  I guess it could be used for "on" style event handler
declarations.  Hmm, you could even craft your own case statement with
his suggestion:

  switch(expr):
    case(val1):
      block1
    case(val2):
      block2
    default:
      block3

This actually makes me worry -- I didn't plan thunks to be the answer
to all problems.  A new idea that could cause a paradigm landslide is
not necessarily right.

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

------- Forwarded Message

Date:    Sat, 01 Feb 2003 02:39:24 -0600
From:    Glyph Lefkowitz <glyph@twistedmatrix.com>
To:      guido@python.org
Subject: proposed syntax additions ++

- ----Security_Multipart(Sat_Feb__1_02:39:24_2003_152)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit


I read about your syntax proposal:

    http://mail.python.org/pipermail/python-dev/2003-January/032608.html

+2!!!

I don't have time to marshal my thoughts at the moment (I should really be
sleeping!), but I wanted to get this out to you as soon as I read it.  This is
terrific.  The ability to introduce new blocks without abusing a keyword would
be a godsend for Twisted.  I would like to introduce a section into my
Deferreds paper talking about how this could be used to improve the current
state of affairs wrt long expressions.  It would be particularly nice if the
syntax were able to accomodate namespace modifications before evaluation.  For
example:

    foo.callRemote("testMethod"):
        andThen:
            print result
        orElse(RemoteException):
            print 'HLUARG die mutant'
        orElse(KeyError):
            print 'key not found'

Deferred could easily stuff thunk-generators into the namespace to provide that
prettying-up.  This would of course be shorthand for:

    d = foo.callRemote('testMethod')
    d.addCallback:
        print result
    d.addErrback:
        failure.trap(RemoteException)
        print 'HLUARG die mutant'
    d.addErrback:
        failure.trap(KeyError)
        print 'key not found'

or something very similar.  I think the former is prettier and I could probably
come up with more substantial applications given some thought.  I have some
particularly deferred-heavy prototype code right now that I estimate would be
reduced by half in length with a syntax facility like this.

If you feel this is coherent feel free to forward to python-dev or wherever.

- -- 
 |    <`'>    |  Glyph Lefkowitz: Travelling Sorcerer  |
 |   < _/ >   |  Lead Developer,  the Twisted project  |
 |  < ___/ >  |      http://www.twistedmatrix.com      |

- ----Security_Multipart(Sat_Feb__1_02:39:24_2003_152)--
Content-Type: application/pgp-signature
Content-Transfer-Encoding: 7bit

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

iD8DBQA+O4e8vVGR4uSOE2wRAqoHAKCqe2bCfPE8/k1RFiUQYz79a9qEdwCgjnhL
e38aEc87UTIvWg0PFwh0tgM=
=Daue
- -----END PGP SIGNATURE-----

- ----Security_Multipart(Sat_Feb__1_02:39:24_2003_152)----

------- End of Forwarded Message