Re: [Python-Dev] Re: anonymous blocks

2005-04-27 Thread Guido van Rossum
I've written a PEP about this topic. It's PEP 340: Anonymous Block Statements (http://python.org/peps/pep-0340.html). Some highlights: - temporarily sidestepping the syntax by proposing 'block' instead of 'with' - __next__() argument simplified to StopIteration or ContinueIteration instance -

[Python-Dev] Another Anonymous Block Proposal

2005-04-27 Thread Jason Diamond
Hi. I hope you don't mind another proposal. Please feel free to tear it apart. A limitation of both Ruby's block syntax and the new PEP 340 syntax is the fact that they don't allow you to pass in more than a single anonymous block parameter. If Python's going to add anonymous blocks, shouldn't

Re: [Python-Dev] Another Anonymous Block Proposal

2005-04-27 Thread Jason Diamond
Paul Svensson wrote: You're not mentioning scopes of local variables, which seems to be the issue where most of the previous proposals lose their balance between hairy and pointless... My syntax is just sugar for nested defs. I assumed the scopes of local variables would be identical when

[Python-Dev] Re: Re: anonymous blocks

2005-04-27 Thread Fredrik Lundh
Guido van Rossum wrote: I've written a PEP about this topic. It's PEP 340: Anonymous Block Statements (http://python.org/peps/pep-0340.html). Some highlights: - temporarily sidestepping the syntax by proposing 'block' instead of 'with' - __next__() argument simplified to StopIteration or

Re: [Python-Dev] Re: anonymous blocks

2005-04-27 Thread Jim Fulton
Guido van Rossum wrote: I've written a PEP about this topic. It's PEP 340: Anonymous Block Statements (http://python.org/peps/pep-0340.html). Some highlights: - temporarily sidestepping the syntax by proposing 'block' instead of 'with' - __next__() argument simplified to StopIteration or

Re: [Python-Dev] Re: anonymous blocks

2005-04-27 Thread Duncan Booth
Jim Fulton [EMAIL PROTECTED] wrote in news:[EMAIL PROTECTED]: Guido van Rossum wrote: I've written a PEP about this topic. It's PEP 340: Anonymous Block Statements (http://python.org/peps/pep-0340.html). Some observations: 1. It looks to me like a bare return or a return with an EXPR3

Re: [Python-Dev] Re: anonymous blocks

2005-04-27 Thread Samuele Pedroni
Jim Fulton wrote: Duncan Booth wrote: Jim Fulton [EMAIL PROTECTED] wrote in news:[EMAIL PROTECTED]: Guido van Rossum wrote: I've written a PEP about this topic. It's PEP 340: Anonymous Block Statements (http://python.org/peps/pep-0340.html). Some observations: 1. It looks to me like a bare return

Re: [Python-Dev] Re: anonymous blocks

2005-04-27 Thread Duncan Booth
Jim Fulton [EMAIL PROTECTED] wrote in news:[EMAIL PROTECTED]: No, the return sets a flag and raises StopIteration which should make the iterator also raise StopIteration at which point the real return happens. Only if exc is not None The only return in the pseudocode is inside if exc is

Re: [Python-Dev] Re: anonymous blocks

2005-04-27 Thread Phillip J. Eby
At 12:30 AM 4/27/05 -0700, Guido van Rossum wrote: I've written a PEP about this topic. It's PEP 340: Anonymous Block Statements (http://python.org/peps/pep-0340.html). Some highlights: - temporarily sidestepping the syntax by proposing 'block' instead of 'with' - __next__() argument simplified to

[Python-Dev] Re: Re: anonymous blocks

2005-04-27 Thread Fredrik Lundh
Phillip J. Eby wrote: This interest is unrelated to anonymous blocks in any case; it's about being able to simulate lightweight pseudo-threads ala Stackless, for use with Twisted. I can do this now of course, but yield expressions as described in PEP 340 would eliminate the need for the

Re: [Python-Dev] Another Anonymous Block Proposal

2005-04-27 Thread Josiah Carlson
Jason Diamond [EMAIL PROTECTED] wrote: Paul Svensson wrote: You're not mentioning scopes of local variables, which seems to be the issue where most of the previous proposals lose their balance between hairy and pointless... My syntax is just sugar for nested defs. I assumed the

Re: [Python-Dev] Re: anonymous blocks

2005-04-27 Thread Josiah Carlson
Guido van Rossum [EMAIL PROTECTED] wrote: I've written a PEP about this topic. It's PEP 340: Anonymous Block Statements (http://python.org/peps/pep-0340.html). Some highlights: - temporarily sidestepping the syntax by proposing 'block' instead of 'with' - __next__() argument simplified

Re: [Python-Dev] Re: anonymous blocks

2005-04-27 Thread Guido van Rossum
I would think that the relevant psuedo-code should look more like: except StopIteration: if ret: return exc if exc is not None: raise exc # XXX See below break Thanks! This was a bug in

Re: [Python-Dev] Re: anonymous blocks

2005-04-27 Thread Steven Bethard
On 4/27/05, Guido van Rossum [EMAIL PROTECTED] wrote: I've written a PEP about this topic. It's PEP 340: Anonymous Block Statements (http://python.org/peps/pep-0340.html). So block-statements would be very much like for-loops, except: (1) iter() is not called on the expression (2) the fact

Re: [Python-Dev] Re: anonymous blocks

2005-04-27 Thread Guido van Rossum
Your code for the translation of a standard for loop is flawed. From the PEP: for VAR1 in EXPR1: BLOCK1 else: BLOCK2 will be translated as follows: itr = iter(EXPR1) arg = None while True: try:

[Python-Dev] ZipFile revision....

2005-04-27 Thread Schollnick, Benjamin
Folks, There's been a lot of talk lately about changes to the ZipFile module... Along with people stating that there are few real life applications for it Here's a small gift... A Quick Backup utility for your files Example:

RE: [Python-Dev] Re: anonymous blocks

2005-04-27 Thread Andrew Koenig
that we are having this discussion at all seems a signal that the semantics are likely too subtle. I feel like we're quietly, delicately tiptoeing toward continuations... ___ Python-Dev mailing list Python-Dev@python.org

Re: [Python-Dev] Re: anonymous blocks

2005-04-27 Thread Josiah Carlson
Guido van Rossum [EMAIL PROTECTED] wrote: Ouch. Another bug in the PEP. It was late. ;-) The finally: should have been except StopIteration: I've updated the PEP online. Unless it is too early for me, I believe what you wanted is... itr = iter(EXPR1) arg = None

Re: [Python-Dev] Re: anonymous blocks

2005-04-27 Thread Brett C.
Guido van Rossum wrote: I've written a PEP about this topic. It's PEP 340: Anonymous Block Statements (http://python.org/peps/pep-0340.html). Some highlights: - temporarily sidestepping the syntax by proposing 'block' instead of 'with' - __next__() argument simplified to StopIteration or

Re: [Python-Dev] Re: anonymous blocks

2005-04-27 Thread Guido van Rossum
[Phillip Eby] Very nice. It's not clear from the text, btw, if normal exceptions can be passed into __next__, and if so, whether they can include a traceback. If they *can*, then generators can also be considered co-routines now, in which case it might make sense to call blocks coroutine

Re: [Python-Dev] Re: anonymous blocks

2005-04-27 Thread Guido van Rossum
I feel like we're quietly, delicately tiptoeing toward continuations... No way we aren't. We're not really adding anything to the existing generator machinery (the exception/value passing is a trivial modification) and that is only capable of 80% of coroutines (but it's the 80% you need most

Re: [Python-Dev] Re: anonymous blocks

2005-04-27 Thread David Ascher
On 4/27/05, Guido van Rossum [EMAIL PROTECTED] wrote: As long as I am BDFL Python is unlikely to get continuations -- my head explodes each time someone tries to explain them to me. You just need a safety valve installed. It's outpatient surgery, don't worry. --david

Re: [Python-Dev] Re: anonymous blocks

2005-04-27 Thread Phillip J. Eby
At 01:27 PM 4/27/05 -0700, Guido van Rossum wrote: [Phillip Eby] Very nice. It's not clear from the text, btw, if normal exceptions can be passed into __next__, and if so, whether they can include a traceback. If they *can*, then generators can also be considered co-routines now, in which

RE: [Python-Dev] Re: switch statement

2005-04-27 Thread Michael Chermside
Guido writes: You mean like this? if x 0: ...normal case... elif y 0: abnormal case... else: ...edge case... You have guts to call that bad style! :-) Well, maybe, but this: if x == 1: do_number_1() elif x == 2:

Re: [Python-Dev] Re: anonymous blocks

2005-04-27 Thread Guido van Rossum
[Guido] I'm not sure what the relevance of including a stack trace would be, and why that feature would be necessary to call them coroutines. [Phillip] Well, you need that feature in order to retain traceback information when you're simulating threads with a stack of generators. Although you

Re: [Python-Dev] Re: switch statement

2005-04-27 Thread Shane Hathaway
Michael Chermside wrote: if x == 1:|if condition_1: do_1() |y = 1 elif x == 2: |elif condition_2: do_2() |y = 2 elif x == 3: |elif condition_3: do_3() |y = 3 else:

Re: [Python-Dev] Re: anonymous blocks

2005-04-27 Thread Guido van Rossum
If the iterator fails to re-raise the StopIteration exception (the spec only says it should, not that it must) I think the return would be ignored but a subsquent exception would then get converted into a return value. I think the flag needs reset to avoid this case. Good catch. I've fixed

Re: [Python-Dev] Re: anonymous blocks

2005-04-27 Thread Guido van Rossum
[Jim Fulton] 2. I assume it would be a hack to try to use block statements to implement something like interfaces or classes, because doing so would require significant local-variable manipulation. I'm guessing that either implementing interfaces (or implementing a class

Re: [Python-Dev] Re: anonymous blocks

2005-04-27 Thread Nick Coghlan
Brett C. wrote: And while the thought is in my head, I think block statements should be viewed less as a tweaked version of a 'for' loop and more as an extension to generators that happens to be very handy for resource management (while allowing iterators to come over and play on the new swing set

Re: [Python-Dev] Re: anonymous blocks

2005-04-27 Thread Nick Coghlan
Guido van Rossum wrote: An alternative that solves this would be to give __next__() a second argument, which is a bool that should be true when the first argument is an exception that should be raised. What do people think? I'll add this to the PEP as an alternative for now. An optional third

Re: [Python-Dev] Integrating PEP 310 with PEP 340

2005-04-27 Thread Guido van Rossum
[Nick Coghlan] This is my attempt at a coherent combination of what I like about both proposals (as opposed to my assortment of half-baked attempts scattered through the existing discussion). PEP 340 has many ideas I like: - enhanced yield statements and yield expressions -

Re: [Python-Dev] Re: anonymous blocks

2005-04-27 Thread Guido van Rossum
[Guido] An alternative that solves this would be to give __next__() a second argument, which is a bool that should be true when the first argument is an exception that should be raised. What do people think? I'll add this to the PEP as an alternative for now. [Nick] An optional third

Re: [Python-Dev] Re: anonymous blocks

2005-04-27 Thread Phillip J. Eby
At 02:50 PM 4/27/05 -0700, Guido van Rossum wrote: [Guido] I'm not sure what the relevance of including a stack trace would be, and why that feature would be necessary to call them coroutines. [Phillip] Well, you need that feature in order to retain traceback information when you're simulating

Re: [Python-Dev] Re: anonymous blocks

2005-04-27 Thread Tim Delaney
Guido van Rossum wrote: - temporarily sidestepping the syntax by proposing 'block' instead of 'with' - __next__() argument simplified to StopIteration or ContinueIteration instance - use continue EXPR to pass a value to the generator - generator exception handling explained +1 A minor sticking

Re: [Python-Dev] Re: anonymous blocks

2005-04-27 Thread Guido van Rossum
[Phillip] Probably my attempt at a *brief* explanation backfired. No, they're not continuations or anything nearly that complicated. I'm just simulating threads using generators that yield a nested generator when they need to do something that might block waiting for I/O. The pseudothread

Re: [Python-Dev] Re: anonymous blocks

2005-04-27 Thread Guido van Rossum
A minor sticking point - I don't like that the generator has to re-raise any ``StopIteration`` passed in. Would it be possible to have the semantics be: If a generator is resumed with ``StopIteration``, the exception is raised at the resumption point (and stored for later use). When

Re: [Python-Dev] Re: anonymous blocks

2005-04-27 Thread Tim Delaney
Guido van Rossum wrote: A minor sticking point - I don't like that the generator has to re-raise any ``StopIteration`` passed in. Would it be possible to have the semantics be: If a generator is resumed with ``StopIteration``, the exception is raised at the resumption point (and stored

Re: [Python-Dev] Re: anonymous blocks

2005-04-27 Thread Guido van Rossum
OK - so what is the point of the sentence:: The generator should re-raise this exception; it should not yield another value. when discussing StopIteration? It forbids returning a value, since that would mean the generator could refuse a break or return statement, which is a little

Re: [Python-Dev] Re: anonymous blocks

2005-04-27 Thread Neil Schemenauer
On Wed, Apr 27, 2005 at 12:30:22AM -0700, Guido van Rossum wrote: I've written a PEP about this topic. It's PEP 340: Anonymous Block Statements (http://python.org/peps/pep-0340.html). [Note: most of these comments are based on version 1.2 of the PEP] It seems like what you are proposing is a

Re: [Python-Dev] Re: anonymous blocks

2005-04-27 Thread Brett C.
Guido van Rossum wrote: [Guido] An alternative that solves this would be to give __next__() a second argument, which is a bool that should be true when the first argument is an exception that should be raised. What do people think? I'll add this to the PEP as an alternative for now.

Re: [Python-Dev] Re: anonymous blocks

2005-04-27 Thread Guido van Rossum
It seems like what you are proposing is a limited form of coroutines. Well, I though that's already what generators were -- IMO there isn't much news there. We're providing a more convenient way to pass a value back, but that's always been possible (see Fredrik's examples). Allowing