[Python-Dev] Generator protocol? (Re: Sets: elt in dict, lst.include)

Greg Ewing greg@cosc.canterbury.ac.nz
Thu, 01 Feb 2001 12:54:45 +1300 (NZDT)

Moshe Zadka <moshez@zadka.site.co.il>:

> Tim's "try to use that to write something that
> will return the nodes of a binary tree" still haunts me.

Instead of an iterator protocol, how about a generator
protocol? Now that we're getting nested scopes, it should
be possible to arrange it so that

  for x in thing:

gets compiled as something like

  def _body(x):

(Actually it would be more complicated than that - for
backward compatibility you'd want a new bytecode that
would look for a __generator__ attribute and emulate
the old iteration protocol otherwise.)

Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg@cosc.canterbury.ac.nz	   +--------------------------------------+