On 22 Jan 2009, at 12:42 , Nick Coghlan wrote:
Tino Wildenhain wrote:
g=(i for i in xrange(1000))[2:5]
g.next() # wrapper would now step 2 times w/o yield and 1 with
yield
2
g.next()
3
g.next()
4
g.next()
Traceback (most recent call last):
File "", line 1, in
StopIteration
as expecte
Nick Coghlan wrote:
Tino Wildenhain wrote:
g=(i for i in xrange(1000))[2:5]
g.next() # wrapper would now step 2 times w/o yield and 1 with yield
2
g.next()
3
g.next()
4
g.next()
Traceback (most recent call last):
File "", line 1, in
StopIteration
as expected - this could be included i
Tino Wildenhain wrote:
>>> g=(i for i in xrange(1000))[2:5]
>>> g.next() # wrapper would now step 2 times w/o yield and 1 with yield
> 2
>>> g.next()
> 3
>>> g.next()
> 4
>>> g.next()
> Traceback (most recent call last):
> File "", line 1, in
> StopIteration
>
> as expected - this could be incl
Hi,
Gerald Britton wrote:
The sieve is just one example. The basic idea is that for some
infinite generator (even a very simple one) you want to cut it off
after some point. As for the number of characters, I spelled lambda
incorrectly (left out a b) and there should be a space after the colon
Terry Reedy wrote:
Cameron Simpson wrote:
Back at uni we had to implement a small language in our compilers class
and the lecturer had specified a proper generic while loop, thus:
loop:
suite
while invariant
suite
endloop
In Python, that is spelled
while True:
suite
if not
Terry Reedy wrote:
> Steven D'Aprano wrote:
>> Is that Xah Lee? It sounds like the sort of thing he'd say.
>
> It was the thread he started, but not him. He contributed other idiocies.
Xah Lee is still around? I would have expected him to get bored and go
away years ago...
Cheers,
Nick.
--
Ni
Cameron Simpson wrote:
> On 21Jan2009 14:02, Tres Seaver wrote:
> | Vitor Bosshard wrote:
> | > BTW, there is already an "until" keyword in python, it's called "while
> not" ;)
> |
> | 'until' is used at least in some languages (Pascal, Modula*, maybe Ada?)
> | for a "terminate at bottom" loop (
Gerald Britton wrote:
> OK then, what is the feeling out there about extending the "for"
> syntax in general (and by extension list comprehensions and generator
> expressions) by adding an optional while clause like this:
>
> for in [while [ | not ]:
>
>
> The predicate would be tested aft
Cameron Simpson wrote:
Back at uni we had to implement a small language in our compilers class
and the lecturer had specified a proper generic while loop, thus:
loop:
suite
while invariant
suite
endloop
In Python, that is spelled
while True:
suite
if not invariant: break
On 21Jan2009 14:02, Tres Seaver wrote:
| Vitor Bosshard wrote:
| > BTW, there is already an "until" keyword in python, it's called "while not"
;)
|
| 'until' is used at least in some languages (Pascal, Modula*, maybe Ada?)
| for a "terminate at bottom" loop (one guaranteed to run at least once):
Steven D'Aprano wrote:
On Wed, 21 Jan 2009 03:10:24 pm Terry Reedy wrote:
Steven D'Aprano wrote:
The three clauses are neither in the same order, nor are they in
reverse order.
They are in the same order but rotated, with the last brought around
to the front to emphasize it. Did you really
In article ,
rdmur...@bitdance.com wrote:
>...
> I understand that you are saying that 'while x' is used in the same
> logical sense ("take a different action when x is no longer true"),
> but that I don't feel that that is enough to say that it has similar
> semantics. Or, perhaps more accurate
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Vitor Bosshard wrote:
>> Some also allow for an "until" keyword. I'm not suggesting that we
>> need to do this in Python; it's just interesting to note that there is
>> some precedent for this approach.
>>
>
> Well, you could propose changing the fo
On Wed, Jan 21, 2009, Gerald Britton wrote:
>
> OK then, what is the feeling out there about extending the "for"
> syntax in general (and by extension list comprehensions and generator
> expressions) by adding an optional while clause like this:
>
> for in [while [ | not ]:
>
What I sugges
The following was supposed to go to the list:
18:29 Gerald Britton:
Yes you could have long lines, but you wouldn't have to use it. You
could still code it up as you would today. It might be convenient for
shorter expressions though.
12:12 PM Ludvig Ericson:
On Jan 21, 2009, at 16:51, Gera
9 11:38:01
>> Asunto: Re: [Python-Dev] PEP 3142: Add a "while" clause to generator
>> expressions
>>
>> FWIW, there are a few historic languages that implement a compound
>> for-loop: Algol 68, PL/I, SAS et al allow constructs that, if
>> translat
- Mensaje original
> De: Gerald Britton
> Para: rdmur...@bitdance.com
> CC: python-dev@python.org
> Enviado: miércoles, 21 de enero, 2009 11:38:01
> Asunto: Re: [Python-Dev] PEP 3142: Add a "while" clause to generator
> expressions
>
> FWIW, there
FWIW, there are a few historic languages that implement a compound
for-loop: Algol 68, PL/I, SAS et al allow constructs that, if
translated to an equivalent (currently invalid) Python-style syntax
would look like this"
for in while :
Some also allow for an "until" keyword. I'm not suggest
On Wed, 21 Jan 2009 at 21:46, Steven D'Aprano wrote:
On Wed, 21 Jan 2009 03:10:24 pm Terry Reedy wrote:
It is a carefully designed 1 to
1 transformation between multiple nested statements and a single
expression.
I'm sure that correspondence is obvious to some, but it wasn't obvious
to me, and
On Wed, 21 Jan 2009 03:10:24 pm Terry Reedy wrote:
> Steven D'Aprano wrote:
...
> > In a generator expression, we have:
> >
> > yielded-expr for-clause if-clause
> >
> > while the corresponding nested statements are:
> >
> > for-clause if-clause yielded-expr
> >
> > The three clauses are neither
Steven D'Aprano wrote:
Another argument against the PEP was that it breaks the correspondence
between the generator expression and the equivalent for-loop. I had
never even noticed such correspondence before, because to my eyes the
most important term is the yielded expression, not the scaffo
Gerald Britton wrote:
I wonder if this is a bug?
It is a known glitch reported last summer. Devs decided not to fix
because doing so would, in the patches tried, slow list comps
significantly. Also, the documented intent and expected usage of
StopIteration is this
"exception StopIteratio
On Wed, 21 Jan 2009 03:56:06 am Antoine Pitrou wrote:
> Alexey G. Shpagin udmvt.ru> writes:
> > Example will look like
> > g = (n for n in range(100) if n*n < 50 or else_break())
>
> Please don't suggest any hack involving raising StopIteration as part
> of a conditional statement in a generator
Gerald Britton wrote:
> I wonder if this is a bug?
Nope, it's part of the defined behaviour. Avoiding the overhead of the
GE machinery is actually the main advantage in using a comprehension
over the equivalent generator expression. Deliberately raising
StopIteration is about the only way to notic
Antoine Pitrou wrote:
> Alexey G. Shpagin udmvt.ru> writes:
>> Example will look like
>> g = (n for n in range(100) if n*n < 50 or else_break())
>
> Please don't suggest any hack involving raising StopIteration as part of a
> conditional statement in a generator expression. It might work today,
On Tue, 20 Jan 2009 at 16:56, Antoine Pitrou wrote:
Alexey G. Shpagin udmvt.ru> writes:
Example will look like
g = (n for n in range(100) if n*n < 50 or else_break())
Please don't suggest any hack involving raising StopIteration as part of a
conditional statement in a generator expression.
n-dev@python.org
>>> Enviado: martes, 20 de enero, 2009 11:18:24
>>> Asunto: Re: [Python-Dev] PEP 3142: Add a "while" clause to generator
>>> expressions
>>>
>>> May I suggest you this variant?
>>>
>>> def raiseStopIteration():
I wonder if this is a bug?
On Tue, Jan 20, 2009 at 11:32 AM, Vitor Bosshard wrote:
> - Mensaje original
>> De: "python-3...@udmvt.ru"
>> Para: Gerald Britton
>> CC: python-dev@python.org
>> Enviado: martes, 20 de enero, 2009 11:18:24
>> Asun
On Tue, Jan 20, 2009 at 12:00 PM, Vitor Bosshard wrote:
>
>
> - Mensaje original
>> De: Gerald Britton
>> Para: Vitor Bosshard
>> CC: python-3...@udmvt.ru; python-dev@python.org
>> Enviado: martes, 20 de enero, 2009 13:40:07
>> Asunto: Re: [Python
- Mensaje original
> De: Gerald Britton
> Para: Vitor Bosshard
> CC: python-3...@udmvt.ru; python-dev@python.org
> Enviado: martes, 20 de enero, 2009 13:40:07
> Asunto: Re: [Python-Dev] PEP 3142: Add a "while" clause to generator
> expressions
>
>
Alexey G. Shpagin udmvt.ru> writes:
>
> Example will look like
> g = (n for n in range(100) if n*n < 50 or else_break())
Please don't suggest any hack involving raising StopIteration as part of a
conditional statement in a generator expression. It might work today, but it
might as well break to
2009 11:18:24
>> Asunto: Re: [Python-Dev] PEP 3142: Add a "while" clause to generator
>> expressions
>>
>> May I suggest you this variant?
>>
>> def raiseStopIteration():
>> raise StopIteration
>>
>> g = (n for n in
- Mensaje original
> De: "python-3...@udmvt.ru"
> Para: Gerald Britton
> CC: python-dev@python.org
> Enviado: martes, 20 de enero, 2009 11:18:24
> Asunto: Re: [Python-Dev] PEP 3142: Add a "while" clause to generator
> expressions
>
>
On 1/20/2009 4:45 PM, Gerald Britton wrote:
OK, so your suggestion:
g = (n for n in range(100) if n*n < 50 or raiseStopIteration())
really means "return in in the range 0-99 if n-squared is less than 50
or the function raiseStopIteration() returns True".
How would this get the generator to st
Yup, I tried your idea and it does work as I intended. It looks a
little better than using takewhile, but not (to me anyway) as nice as
my original suggestion. Still, if my idea is ultimately rejected
(looks that way at the moment), this is a good alternative.
On Tue, Jan 20, 2009 at 10:57 AM, A
On Tue, Jan 20, 2009 at 10:45:27AM -0500, Gerald Britton wrote:
> OK, so your suggestion:
>
> g = (n for n in range(100) if n*n < 50 or raiseStopIteration())
>
> really means "return in in the range 0-99 if n-squared is less than 50
> or the function raiseStopIteration() returns True".
>
> How
OK, so your suggestion:
g = (n for n in range(100) if n*n < 50 or raiseStopIteration())
really means "return in in the range 0-99 if n-squared is less than 50
or the function raiseStopIteration() returns True".
How would this get the generator to stop once n*n >=50? It looks
instead like the fi
On Tue, Jan 20, 2009 at 09:24:32AM -0500, Gerald Britton wrote:
> hmmm...doesn't:
>
> if n*n < 50 or raise StopIteration()
>
> really mean, "Return an integer in the range 0-99 if n-squared is less
> than fifty or the statement 'raise StopIteration()' returns True" ?
>
> I'm not sure that th
On Mon, Jan 19, 2009 at 10:10:00AM -0500, Gerald Britton wrote:
> Please find below PEP 3142: Add a "while" clause to generator
> expressions. I'm looking for feedback and discussion.
>
...
> g = (n for n in range(100) while n*n < 50)
May I suggest you this variant?
def raiseStopI
hmmm...doesn't:
if n*n < 50 or raise StopIteration()
really mean, "Return an integer in the range 0-99 if n-squared is less
than fifty or the statement 'raise StopIteration()' returns True" ?
I'm not sure that that will work.
On Tue, Jan 20, 2009 at 9:18 AM, wrote:
> On Mon, Jan 19, 2009
Kristján Valur Jónsson wrote:
> Are you all certain that this mapping from a generator expression to
> a foor loop isn't just a happy coincidence? After all, the generator
> statement is just a generalization of the list comprehension and that
> doesn't map quite so directly.
The mapping of the fo
On 19Jan2009 19:42, Calvin Spealman wrote:
| OK, I still don't like the general idea, but I have a suggestion for
| what I think is a more favorable syntax, anyway. Basically, adding the
| allowance of an 'else break' when there is an if clause in a generator
| expression or list comprehension. I
OK, I still don't like the general idea, but I have a suggestion for
what I think is a more favorable syntax, anyway. Basically, adding the
allowance of an 'else break' when there is an if clause in a generator
expression or list comprehension. I still dont think it should be
done, but it is a more
Kristján Valur Jónsson wrote:
Are you all certain that this mapping from a generator expression to
a foor loop isn't just a happy coincidence?
Yes, The manual *defines* the meaning of a comprehension in terms of the
corresponding nested statements.
"The comprehension consists of a single exp
Sent: 19. janúar 2009 17:52
To: python-dev@python.org
Subject: Re: [Python-Dev] PEP 3142: Add a "while" clause to generator
expressions
The other, posted by Steven Bethard, is that it fundamentally breaks the
current semantics of abbreviating (except for iteration variable
scoping) an '
Steven Bethard wrote:
> -1. As I pointed out on python-ideas, this proposal makes "while" mean
> something different in a generator expression.
While I initially found the suggestion in the PEP rather cute, that
isn't enough to make it a good idea as a language addition.
So, -1 for a few reasons:
On 1/19/2009 6:51 PM, Terry Reedy wrote:
The other, posted by Steven Bethard, is that it fundamentally breaks the
current semantics of abbreviating (except for iteration variable
scoping) an 'equivalent' for loop.
The proposed syntax would suggest that this should be legal as well:
for i in
On Mon, Jan 19, 2009 at 10:03, Gerald Britton wrote:
> Duly noted and thanks for the feedback! (just what I was looking for
> actually). I do disagree with the idea that the proposal, if
> implemented, would make Python harder to learn. Not sure who would
> find it harder. Having to find and u
2009/1/19 Vitor Bosshard :
> Are you even sure the list comprehension doesn't already shortcut evaluation?
>
> This quick test in 2.6 hints otherwise:
>
>
a = (i for i in range(10) if i**2<10)
Yes, but your test, once it becomes true, remains so. Consider
>>> list(n for n in range(10) if n%2
On Mon, Jan 19, 2009 at 1:41 PM, Scott Dial
wrote:
> Vitor Bosshard wrote:
>> Are you even sure the list comprehension doesn't already shortcut evaluation?
>
> It does not. The body of the comprehension is evaluated all the way to
> completion, ..
In addition, the test is evaluated on all items a
2009/1/19 Vitor Bosshard
>
>
>
>
> - Mensaje original
> > De: Gerald Britton
> > Para: Terry Reedy
> > CC: python-dev@python.org
> > Enviado: lunes, 19 de enero, 2009 15:03:47
> > Asunto: Re: [Python-Dev] PEP 3142: Add a "while" c
Vitor Bosshard wrote:
> Are you even sure the list comprehension doesn't already shortcut evaluation?
It does not. The body of the comprehension is evaluated all the way to
completion, despite the fact that a.next() does not return until there
is a successful test of the if expression.
>>> def pr
- Mensaje original
> De: Gerald Britton
> Para: Terry Reedy
> CC: python-dev@python.org
> Enviado: lunes, 19 de enero, 2009 15:03:47
> Asunto: Re: [Python-Dev] PEP 3142: Add a "while" clause to generator
> expressions
>
> Duly noted and thanks f
Duly noted and thanks for the feedback! (just what I was looking for
actually). I do disagree with the idea that the proposal, if
implemented, would make Python harder to learn. Not sure who would
find it harder. Having to find and use takewhile was harder for me.
I still find that one counter-
Gerald Britton wrote:
Please find below PEP 3142: Add a "while" clause to generator
expressions. I'm looking for feedback and discussion.
This was already discussed on python-ideas where it got negative feedback.
One objection, mentioned by Mathias Panzerbock and Georg Brandl, is that
it is
On Mon, Jan 19, 2009 at 7:10 AM, Gerald Britton
wrote:
> PEP: 3142
> Title: Add a "while" clause to generator expressions
[snip]
> numbers in that range. Allowing for a "while" clause would allow
> the redundant tests to be short-circuited:
>
> g = (n for n in range(100) while n*n < 50)
>
On Mon, Jan 19, 2009 at 11:41 AM, Gerald Britton
wrote:
> Thanks Calvin,
>
> Could you please expand on your thoughts about possible confusion?
> That is, how do you see a programmer becoming confused if this option
> were added to the syntax.
I think that the difference between these two lines i
The sieve is just one example. The basic idea is that for some
infinite generator (even a very simple one) you want to cut it off
after some point. As for the number of characters, I spelled lambda
incorrectly (left out a b) and there should be a space after the colon
to conform to design guides.
On Mon, Jan 19, 2009 at 10:37 AM, Gerald Britton
wrote:
>prime = (p for p in sieve() while p < 1000)
>prime = takewhile(lamda p:p<1000, sieve())
>
I'm pretty sure the extra cost of evaluating the lambda at each step is tiny
compared to the cost of the sieve, so I don't you can make a conv
2009/1/19 Gerald Britton :
> Could you please expand on your thoughts about possible confusion?
> That is, how do you see a programmer becoming confused if this option
> were added to the syntax.
My main concern about confusion is that you're adding a "while" that
actually will behave like a "bre
Thanks Calvin,
Could you please expand on your thoughts about possible confusion?
That is, how do you see a programmer becoming confused if this option
were added to the syntax.
On Mon, Jan 19, 2009 at 11:29 AM, Calvin Spealman wrote:
> I am really unconvinced of the utility of this proposal and
Sure: Say I implement the sieve of Eratosthenes as a prime number
generator. I want some primes for my application but there are an
infinite number of primes. So I would like to write:
prime = (p for p in sieve() while p < 1000)
instead of:
import itertools
prime = takewhile(lamda
I am really unconvinced of the utility of this proposal and quite
convinced of the confusing factor it may well add to the current
syntax. I would like to see more applicable examples. It would replace
uses of takewhile, but that isn't a really often used function. So, is
there any evidence to supp
On Mon, Jan 19, 2009 at 9:10 AM, Gerald Britton wrote:
> g = (n for n in range(100) if n*n < 50)
>
> would yield 0, 1, 2, 3, 4, 5, 6 and 7, but would also consider
> the numbers from 8 to 99 and reject them all since n*n >= 50 for
> numbers in that range. Allowing for a "while" clause wou
On Mon, Jan 19, 2009 at 9:10 AM, Gerald Britton
wrote:
> Please find below PEP 3142: Add a "while" clause to generator
> expressions. I'm looking for feedback and discussion.
>
>
> PEP: 3142
> Title: Add a "while" clause to generator expressions
> Version: $Revision: 68715 $
> Last-Modified: $Dat
Please find below PEP 3142: Add a "while" clause to generator
expressions. I'm looking for feedback and discussion.
PEP: 3142
Title: Add a "while" clause to generator expressions
Version: $Revision: 68715 $
Last-Modified: $Date: 2009-01-18 11:28:20 +0100 (So, 18. Jan 2009) $
Author: Gerald Britt
66 matches
Mail list logo