[Python-Dev] accumulator display syntax

Skip Montanaro skip at pobox.com
Fri Oct 17 14:57:46 EDT 2003

    >> But, indexing does stretch quite far in the current Python syntax and
    >> semantics (in Python's *pragmatics* you're supposed to use it far
    >> more restrainedly).

    Guido> Which is why I didn't like the 'sum[x for x in S]' notation much.
    Guido> Let's look for an in-line generator notation instead.  I like

    Guido>   sum((yield x for x in S))

    Guido> but perhaps we can make this work:

    Guido>   sum(x for x in S)

Forgive my extreme density on this matter, but I don't understand what

    (yield x for x in S)

is supposed to do.  Is it supposed to return a generator function which I
can assign to a variable (or pass to the builtin function sum() as in your
example) and call later, or is it supposed to turn the current function into
a generator function (so that each executed yield statement returns a value
to the caller of the current function)?

Assuming the result is a generator function (a first class object I can
assign to a variable then call later), is there some reason the current
function notation is inadequate?  This seems to me to suffer the same
expressive shortcomings as lambda.  Lambda seems to be hanging on by the
hair on its chinny chin chin.  Why is this construct gaining traction?  If
you don't like lambda, I can't quite see why syntax this is all that

OTOH, if lambda: x: x+1 is okay, then why not:

    yield: x for x in S



More information about the Python-Dev mailing list