[Python-Dev] accumulator display syntax

Greg Ewing greg at cosc.canterbury.ac.nz
Wed Oct 22 21:49:45 EDT 2003


Tim Peters <tim_one at email.msn.com>:

> If will if the "p" and "pipe" in the generator expression use the
> bindings in effect at the time the generator expression is assigned to
> pipe.

Lying awake thinking about this sort of thing last night,
I found myself wondering if there should be a way of
explicitly requesting that a name be evaluated at closure 
creation time, e.g.

    pipe = source
    for p in predicates:
        pipe = e for e in pipe if ^p(e)

where the ^ means that p is evaluated in the enclosing
scope when the closure is created, and bound to a slot
which behaves like a default-argument slot (but is
separate from the default arguments).

This would allow the current delayed-evaluation semantics
to be kept as the default, while eliminating any need
for using the default-argument hack when you don't
want delayed evaluation.

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



More information about the Python-Dev mailing list