[Python-bugs-list] [ python-Feature Requests-778859 ] Make the generators working like Sather iterator
SourceForge.net
noreply@sourceforge.net
Mon, 28 Jul 2003 06:23:25 -0700
Feature Requests item #778859, was opened at 2003-07-28 12:52
Message generated for change (Comment added) made by shasckaw
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=778859&group_id=5470
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Shasckaw Lionfaith (shasckaw)
Assigned to: Nobody/Anonymous (nobody)
Summary: Make the generators working like Sather iterator
Initial Comment:
Primarly, it would only be a syntaxic sugar. But it can
lead to some unexpected opitmisations.
The feature would allow this:
def upto(first, last):
x=first
while x<=last:
yield x
x=x+1
x=upto(1, 10)
try:
while 1:
print x.next()
except StopIteration:
print "End of loop"
To be written like in Sather or something near it:
def upto(first, last):
#same definition as above
loop:
print upto!(1, 10)
finally:
print "End of loop"
As you can see, it's shorter, smarter, and more easy to
understand. The '!' in upto!(1, 10) is important to
emphasize its rôle as a generator. The creators of
Sather tell that this technique can lead to a very high
optimisation of loops.
I hope that this request will be deeply studied because
it is really worth of it.
----------------------------------------------------------------------
>Comment By: Shasckaw Lionfaith (shasckaw)
Date: 2003-07-28 15:23
Message:
Logged In: YES
user_id=824691
My example was too simple, sorry.
Here is a doc page about satheric iterators:
http://www.gnu.org/software/sather/Doc/tutorial.html/iterators873.html
And the next one is also pretty interesting.
With the satheric way to write it, one would be able to do this:
loop:
a=range!(1,10)
if test(a):
b=range!(1,10)
print "("+ a + "," + "b" + ")"
My error is repaired now! :)
The first iterator to stop stop the loop.
----------------------------------------------------------------------
Comment By: Barry A. Warsaw (bwarsaw)
Date: 2003-07-28 14:22
Message:
Logged In: YES
user_id=12800
The Pythonic way to write the latter (after the def) is:
for x in upto(1, 10):
print x
else:
print 'end of loop'
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=778859&group_id=5470