[Python-ideas] Reversable
cool-RR
cool-rr at cool-rr.com
Fri Apr 30 00:47:58 CEST 2010
On Fri, Apr 30, 2010 at 12:33 AM, Paul Moore <p.f.moore at gmail.com> wrote:
> On 29 April 2010 12:22, cool-RR <cool-rr at cool-rr.com> wrote:
> > Yes, I'm aware the implementation is simple. I was not asking for an
> > implementation. I was just raising the idea that it should be part of the
> > builtin `reversed`. But since there are no +1s, I guess not.
>
> Sorry. My point was that the gains (in terms of the difficulty of
> implementing it yourself) are minor, so the cost doesn't justify it.
> Specifically, the costs are (1) extra complexity when describing the
> behaviour of reversed() and (2) more seriously, potential crashes if
> an infinite generator (for example) is passed to reversed() in error.
>
> Currently, reversed(infinite_gen) is a trappable error. With your
> proposal, it would halt the program until all memory was consumed,
> then crash. Anyone using a custom function such as my
> reversed_anything can be assumed to understand its limitations,
> whereas builtins can be assumed to behave "nicely".
>
> Looking at it the other way, it's easy to build reversed_anything
> given reversed, but it's not possible to build reversed given only
> reversed_anything. The builtin function should be the one that can be
> more easily used to build from.
>
> My apologies for being too terse.
> Paul.
>
Thanks for the apology Paul.
As I said in my message before, I proposed having an argument to `reversed`
which will cause this "violent reverse" behavior. I didn't say I want
`reversed` to do it by default. Like, I suggest you could do
`reversed(iterator, violent=True)`, and only that will cause the iterator to
be copied to a list before getting reversed.
Though actually, I don't feel very strongly about this issue. I was just
raising it to see whether it happened to be something that bothered other
people as well, and then maybe it would have been worth doing something
about. But it seems that it isn't, so I should probably let it go.
Thanks for your attention,
Ram.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20100430/1b102d61/attachment.html>
More information about the Python-ideas
mailing list