Prothon gets Major Facelift in Vers 0.1.0 [Prothon]

Josiah Carlson jcarlson at uci.edu
Mon May 24 20:06:02 EDT 2004


> See http://prothon.org.

You use inconsistant descriptions of generators here:
http://prothon.org/tutorial/tutorial11.htm#gen

First you say that all generators must use 'gen' rather than 'def', but 
in your example you mix the two...

gen evenOdds(max):
     def evens(max):
         (body contains a yield)

Based on that same portion of your tutorial, it is not clear that your 
example...

gen evenOdds(max):
     def evens(max):
         num = 0
         while num < max:
             yield num
             num += 2

     def odds(max):
         num = 1
         while num < max:
             yield num
             num += 2

     evens(max)
     odds(max)

for i in evenOdds(10):
     print i,   #  prints 0 2 4 6 8 1 3 5 7 9

Actually should produce what you say it should.

Perhaps it is my background in Python that says unless you manually 
iterate through evens(max) and odds(max), yielding values as you go along...
     for i in evens(max): yield i
     for i in odds(max): yield i
...or combine and return the iterator with something like...
     return itertools.chain(evens(max), odds(max))
..., you will get nothing when that generator function is evaluated.

I believe that either your documentation or example needs to be fixed.

  - Josiah



More information about the Python-list mailing list