pre-PEP: Simple Thunks

Kay Schluehr kay.schluehr at gmx.net
Sat Apr 16 11:07:16 EDT 2005


Brian Sabbey wrote:

> def get_items(thunk):    # <-- "thunk-accepting function"
>      f = acquire()
>      try:
>          for i in f:
>              thunk(i)      # A-OK
>      finally:
>          f.release()
>
> do i in get_items():
>     print i

Seems like You want to solve the addressed generator problem by
manipulating the syntax: "make generators look more function like",
because father compiler won't complain ;-) Sorry, but IMO this is
hackery and has nothing to do with good language design and I consider
this as extremely harmfull. Instead of making things explicit it does
it the other way round and tries to make Python code more obscure.
Moreover I can't notice the superiority of thunks in Your other
examples over more common techniques like decorators for pre- and
postconditions and the GOF command pattern. I thinks the place for such
ideas are Michael Hudsons famous bytecodehacks.

-1 for from me for thunks in Python.

Ciao,
Kay




More information about the Python-list mailing list