<div dir="ltr"><div class="gmail_quote">On Tue, Apr 27, 2010 at 12:12 AM, George Sakkis <span dir="ltr"><<a href="mailto:george.sakkis@gmail.com">george.sakkis@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><div></div><div class="h5">On Mon, Apr 26, 2010 at 11:41 PM, cool-RR <<a href="mailto:cool-rr@cool-rr.com">cool-rr@cool-rr.com</a>> wrote:<br>
> On Mon, Apr 26, 2010 at 11:34 PM, George Sakkis <<a href="mailto:george.sakkis@gmail.com">george.sakkis@gmail.com</a>><br>
> wrote:<br>
>><br>
>> On Mon, Apr 26, 2010 at 11:18 PM, cool-RR <<a href="mailto:cool-rr@cool-rr.com">cool-rr@cool-rr.com</a>> wrote:<br>
>> > On Mon, Apr 26, 2010 at 11:13 PM, Xavier Ho <<a href="mailto:contact@xavierho.com">contact@xavierho.com</a>><br>
>> > wrote:<br>
>> >><br>
>> >> On Tue, Apr 27, 2010 at 7:10 AM, cool-RR <<a href="mailto:cool-rr@cool-rr.com">cool-rr@cool-rr.com</a>> wrote:<br>
>> >>><br>
>> >>> Just something small that I thought of, and I haven't thought about<br>
>> >>> this<br>
>> >>> deeply at all, so maybe this is way wrong. But: What about adding a<br>
>> >>> `Reversable` next to all the `Iterable` and `Container` and stuff?<br>
>> >><br>
>> >> You mean there is something Iterable we can't reverse by doing [::-1]<br>
>> >> or<br>
>> >> calling reversed() ? This idea feels a bit too general to be useful.<br>
>> >> Any<br>
>> >> rationales?<br>
>> >><br>
>> >> Cheers,<br>
>> >> Xav<br>
>> ><br>
>> > As far as I know, iterables are generally not reversable. Try defining a<br>
>> > simple iterator, like a class with just an `__iter__` function, and run<br>
>> > `reversed` on it. You get `TypeError: argument to reversed() must be a<br>
>> > sequence`. (Which by the way is a bad error message.)<br>
>> > Am I missing something?<br>
>><br>
>> So what should reversed() (or a new Reversable()) return for, say,<br>
>> itertools.count() ?<br>
>><br>
>> By the way, comp.lang.python [1] or the tutor mailing list [2] are<br>
>> more appropriate than python-ideas for asking<br>
>> questions "you haven't thought about deeply at all".<br>
>><br>
>> George<br>
>><br>
>> [1] <a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
>> [2] <a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/mailman/listinfo/tutor</a><br>
><br>
> I'm not really understanding you, George. Am I getting something very wrong<br>
> here? When you put `itertools.count()` into `reversed()`, you get an error,<br>
> like you should, because it's not a sequence and it doesn't define<br>
> `__reversed__`. So it's not a reversable object. I'm proposing to have a<br>
> `Reversable` similar to `Iterable`, which checks the existence of<br>
> `__reversed__` instead of `__iter__`.<br>
<br>
</div></div>Sorry, it wasn't obvious (to me at least) that you were talking about<br>
the abstract classes under the collections module, and in your second<br>
post you implied (again, that was my understanding at any rate) that<br>
defining a class with just an __iter__ should be acceptable by<br>
`reversed` instead of raising a TypeError.<br>
<br>
On the other hand a collections.Reversable abstract class that checks<br>
specifically for __reversed__ sounds quite reasonable.<br>
<font color="#888888"><br>
George<br>
</font></blockquote></div><br>Does anyone else care to express their opinion about the Reversable suggestion?<div><br></div><div>Ram.<br><div><br>
</div></div></div>