Proposed new syntax

Steve D'Aprano steve+python at pearwood.info
Thu Aug 24 23:33:16 EDT 2017


On Fri, 25 Aug 2017 01:19 pm, Paul Rubin wrote:

> Steve D'Aprano <steve+python at pearwood.info> writes:
>> the public API is to call the next() built-in function, and the
>> implementation is the __next__ dunder.
> 
> In that case it would have been nice to make next() cache the most
> recently generated value from the iterator.  That would make lots of
> code simpler.

Huh? Why?

Did __next__ cache the most recently generated value?

The whole point of next() (whether a method or function) is that it evaluates
the next value on demand, not to return the previous value you already
evaluated earlier. I don't understand what sort of code it would make simpler.

I'm tempted to say "buggy code", but I'll give you the benefit of the doubt
first *wink*



-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.




More information about the Python-list mailing list