@Ethan Furman<div><br></div><div>each call to x(:) would return a different iterator, so both sides will have their own information about where they are. Also it is the case that checking for equality of generators does not make the generators to expand out, so checking for equality becomes to checking if they are the same generator object. The following example shows this</div>
<div><br></div><div>Python3</div><div>>> (x for x in range(10)) == (x for x in range(10))</div><div>False</div><div><br></div><div>@Etienne</div><div><br></div><div>"lambda" is a keyword and would get captured by the lexer, so this should conflict with adding the grammar that would make this work. This is different than function calls because currently arguments of function calls cannot have ":", causing `x(:)` to be a syntax error. The grammar that would have to be added would be mutually exclusive from current functionality.</div>
<div><br></div><div>@Victor</div><div><br></div><div>I was not completely familiar with itertools but <span style>itertools.islice() seems to have the functionality that I propose. It is great that there already exist a solution that does not change python's syntax. Unless anyone wants to pursue this proposal I will drop it next week.</span></div>
<div><span style><br></span></div><div><span style>Thanks for your feedback guys</span></div><div><br></div><div><div class="gmail_quote">On Wed, Mar 21, 2012 at 5:09 PM, Ethan Furman <span dir="ltr"><<a href="mailto:ethan@stoneleaf.us" target="_blank">ethan@stoneleaf.us</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Huan Do wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
*Hi,<div><br>
<br>
I am a graduating Berkeley student that loves python and would like to propose an enhancement to python. My proposal introduces a concept of slicing generator. For instance, if one does x[:] it returns a list which is a copy of x. Sometimes programmers would want to iterate over a slice of x, but they do not like the overhead of constructing another list. Instead we can create a similar operator that returns a generator. My proposed syntax is x(:). The programmers are of course able to set lower, upper, and step size like the following.<br>
<br>
x(1::-1)<br>
</div></blockquote>
<br>
The biggest problem with your proposal is that generators don't remember what they have already yielded, so<br>
<br>
x(:) != x(:) # first time gets everything, second time gets nothing<span><font color="#888888"><br>
<br>
~Ethan~<br>
</font></span></blockquote></div><br></div>