[Python-Dev] Re: Re: accumulator display syntax

Terry Reedy tjreedy at udel.edu
Mon Oct 20 18:42:18 EDT 2003


"Andrew Bennetts" <andrew-pythondev at puzzling.org> wrote in message
...
> I think the lazy iteration syntax approach was probably a better
idea.  I
> don't like the proposed use of "yield" to signify it, though -- 
"yield" is a
> flow control statement, so the examples using it in this thread look
odd to
> me.

Same here.

> Perhaps it would be best to simply use the keyword "lazy" -- after
all,
> that's the key distinguishing feature.  I think my preferred syntax
would
> be:
>
>     sum([lazy x*x for x in sequence])

I like this the best of suggestions so far.  Easy to understand, easy
to teach:
[lazy ...] = iter([...]) but produced more efficiently

> But use of parens instead of brackets, and/or a colon to make the
keyword
> stand out (and look reminisicent to a lambda! which *is* a related
concept,
> in a way -- it also defers evaluation), e.g.:
>
>     sum((lazy: x*x for x in sequence))

I prefer sticking with [...] for 'make a (possibly virtual) list'.
Having removed ':' when abbreviating
_[]
for i in seq: _.append[expr]
as an expression, it seems odd to bring it back for a special case.  I
wish ':' could have also been removed from the lambda abbreviation of
def.

Terry J. Reedy






More information about the Python-Dev mailing list