<br><br><div><span class="gmail_quote">On 8/24/06, <b class="gmail_sendername">Guido van Rossum</b> &lt;<a href="mailto:guido@python.org">guido@python.org</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On 8/24/06, Neal Norwitz &lt;<a href="mailto:nnorwitz@gmail.com">nnorwitz@gmail.com</a>&gt; wrote:<br>&gt; I've been working on enhancing xrange and there are a bunch of issues<br>&gt; to consider.&nbsp;&nbsp;I've got pretty much complete implementations in both C
<br>&gt; and Python.&nbsp;&nbsp;Currently xrange is 2 objects:&nbsp;&nbsp;range and the iter.<br>&gt; These only work on C longs.&nbsp;&nbsp;Here's what I propose:<br>&gt;<br>&gt; 2.6:<br>&gt;&nbsp;&nbsp;* Add deprecation warning if a float is passed to xrange (currently
<br>&gt; silently truncates)<br>&gt;&nbsp;&nbsp;* Allow int, long, float, or obj.__index__<br><br>float? I thought the first bullet says no float?</blockquote><div><br>No, the bullet says 'add warning' :) xrange() currently accepts floats, because it uses one of the integer getargs formats:
<br><br>&gt;&gt;&gt; xrange(1.2, 2.5, 1.9999)<br>xrange(1, 2)<br><br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">&gt;&nbsp;&nbsp;* Implement xrange in python
<br><br>Since xrange is used in performance critical apps that may be a bad<br>idea. Or maybe only if the args aren't all ints?</blockquote><div><br>Is the cost of *calling* xrange() really a big issue? I don't think Neal measured this, but he could. I'd imagine performance-critical apps call xrange() once, then use that to iterate.
</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>&gt; Caveats:<br>&gt;&nbsp;&nbsp;* The generator version above doesn't support floats.&nbsp;&nbsp;We could
<br>&gt; easily support floats with a&nbsp;&nbsp;different calculation that would be<br>&gt; slightly more expensive, but not have accumulated error.<br><br>Is there a good use case for supporting float? The problem with floats<br>
is that even apart from accumulated error, it's still ambiguous. E.g.<br>will xrange(1.1, 1.9, 0.1) include the end point or not? That would<br>depend on the details of decimal-to-binary conversion.</blockquote><div><br>Supporting floats is definately problematic. It would be nice if xrange() supported arbitrary numeric types, though, like decimals. That would quench the thirst people seem to have for float-ish xranges.
<br>&nbsp;</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">&gt;&nbsp;&nbsp;* With a python implementation there is a little bit of bootstraping<br>&gt; that is necessary to get the iter implemented in C into the xrange
<br>&gt; object implemented in Python<br><br>Long-term, I'd rather see it implemented all in C. Short term, the<br>Python implementation is great to experiment.</blockquote><div><br>Why, other than performance? It's a lot simpler and much easier to get right in Python, which is quite good for maintenance, too.
<br></div><br></div>-- <br>Thomas Wouters &lt;<a href="mailto:thomas@python.org">thomas@python.org</a>&gt;<br><br>Hi! I'm a .signature virus! copy me into your .signature file to help me spread!