[Python-checkins] CVS: python/nondist/peps pep-0279.txt,1.2,1.3
Barry Warsaw
bwarsaw@users.sourceforge.net
Mon, 04 Feb 2002 13:03:06 -0800
Update of /cvsroot/python/python/nondist/peps
In directory usw-pr-cvs1:/tmp/cvs-serv9926
Modified Files:
pep-0279.txt
Log Message:
Raymond Hettinger's latest updates.
Index: pep-0279.txt
===================================================================
RCS file: /cvsroot/python/python/nondist/peps/pep-0279.txt,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** pep-0279.txt 2002/02/01 14:55:46 1.2
--- pep-0279.txt 2002/02/04 21:03:03 1.3
***************
*** 8,12 ****
Created: 30-Jan-2002
Python-Version: 2.3
! Post-History:
--- 8,12 ----
Created: 30-Jan-2002
Python-Version: 2.3
! Post-History:
***************
*** 46,50 ****
making generator creation as convenient as list creation.
! 3. Extend the syntax of the 'yield' keyword to enable two way
parameter passing. The resulting increase in power simplifies
the creation of consumer streams which have a complex execution
--- 46,50 ----
making generator creation as convenient as list creation.
! 3. Extend the syntax of the 'yield' keyword to enable generator
parameter passing. The resulting increase in power simplifies
the creation of consumer streams which have a complex execution
***************
*** 58,62 ****
existing implementation and require little additional effort to
incorporate. Each is backward compatible and requires no new
! keywords.
--- 58,63 ----
existing implementation and require little additional effort to
incorporate. Each is backward compatible and requires no new
! keywords. These generator tools go into Python 2.3 when
! generators become final and are not imported from __future__.
***************
*** 150,180 ****
If a list comprehension starts with a 'yield' keyword, then
! express the remainder of the statement as generator. For example:
! g = [yield (len(line),line) for line in file.readline() if len(line)>5]
! print g.next()
! print g.next()
This would be implemented as if it had been written:
! def __temp_gen():
! for line in file.readline():
! if len(line) > 5:
! yield (len(line), line)
! g = __temp_gen()
! print g.next()
! print g.next()
!
! Note A: There is a difference in the above implementation as
! compared to list comprehensions. For a generator comprehension,
! the variables are created in a separate scope while list
! comprehensions use the enclosing scope. If this PEP is accepted,
! the parser should generate byte code that eliminates this
! difference by passing the line variable in the enclosing scope and
! using that same variable passed by reference inside the generator.
! This will make the behavior of generator comprehension identical
! to that of list comprehensions.
! Note B: There is some debate about whether the enclosing brackets
should be part of the syntax for generator comprehensions. On the
plus side, it neatly parallels list comprehensions and would be
--- 151,168 ----
If a list comprehension starts with a 'yield' keyword, then
! express the comprehension with a generator. For example:
! g = [yield (len(line),line) for line in file if len(line)>5]
This would be implemented as if it had been written:
! class __Temp:
! def __iter__(self):
! for line in file:
! if len(line) > 5:
! yield (len(line), line)
! g = __Temp()
! Note A: There is some debate about whether the enclosing brackets
should be part of the syntax for generator comprehensions. On the
plus side, it neatly parallels list comprehensions and would be
***************
*** 191,195 ****
! Specification for two-way Generator Parameter Passing:
1. Allow 'yield' to assign a value as in:
--- 179,183 ----
! Specification for Generator Parameter Passing:
1. Allow 'yield' to assign a value as in:
***************
*** 210,214 ****
is that a value can be sent into the generator. By analogy,
consider the quality improvement from GOSUB (which had no argument
! passing mechanism) to modern procedure calls (which pass in
arguments and return values).
--- 198,202 ----
is that a value can be sent into the generator. By analogy,
consider the quality improvement from GOSUB (which had no argument
! passing mechanism) to modern procedure calls (which can pass in
arguments and return values).
***************
*** 235,239 ****
queues. A class-based approach competes well when there are no
complex execution states or variable states. When the complexity
! increases, generators with two-way communication are much simpler
because they automatically save state (unlike classes which must
explicitly save the variable and execution state in instance
--- 223,227 ----
queues. A class-based approach competes well when there are no
complex execution states or variable states. When the complexity
! increases, generators with parameter passing are much simpler
because they automatically save state (unlike classes which must
explicitly save the variable and execution state in instance
***************
*** 241,245 ****
! Example of a Complex Consumer
The encoder for arithmetic compression sends a series of
--- 229,233 ----
! Example of a Complex Consumer
The encoder for arithmetic compression sends a series of
***************
*** 282,285 ****
--- 270,282 ----
+ Example of a Producer and Consumer Used Together in a Pipelike Fashion
+
+ 'Analogy to: source | upper | sink'
+ sink = sinkgen()
+ sink.next()
+ for word in source():
+ sink.next( word.upper() )
+
+
Specification for Generator Exception Passing:
***************
*** 312,318 ****
already associated with exceptions in other languages.
References
!
[1] PEP 255 Simple Generators
http://python.sourceforge.net/peps/pep-0255.html
--- 309,322 ----
already associated with exceptions in other languages.
+ Note B: The throw syntax should exactly match raise's syntax including:
+ raise string g.throw(string)
+ raise string, data g.throw(string,data)
+ raise class, instance g.throw(class,instance)
+ raise instance g.throw(instance)
+ raise g.throw()
+
References
!
[1] PEP 255 Simple Generators
http://python.sourceforge.net/peps/pep-0255.html
***************
*** 321,325 ****
http://python.sourceforge.net/peps/pep-0212.html
! [3] PEP 202 List Comprehensions
http://python.sourceforge.net/peps/pep-0202.html
--- 325,329 ----
http://python.sourceforge.net/peps/pep-0212.html
! [3] PEP 202 List Comprehensions
http://python.sourceforge.net/peps/pep-0202.html
***************
*** 327,331 ****
tease out these proposals:
! Indexed Function
http://groups.google.com/groups?hl=en&th=33f778d92dd5720a
--- 331,335 ----
tease out these proposals:
! Indexed Function
http://groups.google.com/groups?hl=en&th=33f778d92dd5720a
***************
*** 340,347 ****
Discussion Draft of this PEP
! http://groups.google.com/groups?hl=en&th=df8b5e7709957eb7
[5] Dr. David Mertz's draft column for Charming Python.
! href="http://gnosis.cx/publish/programming/charming_python_b5.txt
--- 344,351 ----
Discussion Draft of this PEP
! http://groups.google.com/groups?hl=en&th=df8b5e7709957eb7
[5] Dr. David Mertz's draft column for Charming Python.
! http://gnosis.cx/publish/programming/charming_python_b5.txt
***************
*** 357,358 ****
--- 361,364 ----
fill-column: 70
End:
+
+