[Python-Dev] accumulator display syntax

Raymond Hettinger python at rcn.com
Mon Oct 20 02:35:49 EDT 2003


[Guido]
> > the proposed notation doesn't return a list.
> > ...
> > I don't have a proposal for generator comprehension syntax though,
and
> > [yield ...] has the same problem.

[Greg Ewing]
> How about just leaving off the brackets?
> 
>   gen = yield x*x for x in stuff

Heck no!

Right now, the only way to tell if a function is a generator
is to read through the code looking for a yield.  If we do
get a generator comprehension syntax, it *must* be distinctively
set-off from the surrounding code.

Brackets accomplish set-off but look too much like lists.
Parens aren't strong enough unless the yield is followed a colon.
Someone suggested paired angle brackets (lt and gt) but that
  was promptly shot down for some reason I can't recall.
Curly braces and quotes are probably out of the question.
That leaves only dollar signs and other perlisms, yuck.

The best so far is (yield: x*x for x in stuff) but someone
very important said they hated it for some reason.

Perhaps someone can come up with some clever, self explanatory
use of --> or some such.


Raymond




More information about the Python-Dev mailing list