1.1 --- a/lib/builtins.py Sun Oct 22 02:58:06 2006 +0200
1.2 +++ b/lib/builtins.py Mon Oct 23 23:59:23 2006 +0200
1.3 @@ -743,6 +743,25 @@
1.4 class undefined:
1.5 pass
1.6
1.7 +class xrange:
1.8 + def __init__(self, start, end, step=1):
1.9 + self.start = start
1.10 + self.end = end
1.11 + self.step = step
1.12 + self.current = start
1.13 +
1.14 + def __iter__(self):
1.15 + return self
1.16 +
1.17 + def next(self):
1.18 + if self.current >= self.end:
1.19 + raise StopIteration
1.20 + current = self.current
1.21 + self.current += self.step
1.22 + return current
1.23 +
1.24 +# General functions.
1.25 +
1.26 def isinstance(obj, cls):
1.27 return boolean()
1.28
1.29 @@ -759,26 +778,29 @@
1.30 max_so_far = i
1.31 return max_so_far
1.32
1.33 +def range(start, end, step=None):
1.34 + if start == end:
1.35 + return []
1.36 + elif start > end:
1.37 + step = step or 1
1.38 + i = start
1.39 + result = []
1.40 + while i < end:
1.41 + result.append(i)
1.42 + i += 1
1.43 + return result
1.44 + else:
1.45 + step = step or -1
1.46 + i = start
1.47 + result = []
1.48 + while i > end:
1.49 + result.append(i)
1.50 + i -= 1
1.51 + return result
1.52 +
1.53 def str(x):
1.54 return x.__str__()
1.55
1.56 -class xrange:
1.57 - def __init__(self, start, end, step=1):
1.58 - self.start = start
1.59 - self.end = end
1.60 - self.step = step
1.61 - self.current = start
1.62 -
1.63 - def __iter__(self):
1.64 - return self
1.65 -
1.66 - def next(self):
1.67 - if self.current >= self.end:
1.68 - raise StopIteration
1.69 - current = self.current
1.70 - self.current += self.step
1.71 - return current
1.72 -
1.73 # Special values. None of these definitions should be generated by the compiler.
1.74 # All such definitions should be made in the underlying implementation.
1.75