# HG changeset patch # User paulb@jeremy # Date 1161640763 -7200 # Node ID 4de15deb3588e7077d1435722b97f503418847f1 # Parent f3a0c40b75a1423f2038b6597a38d245d3bbdcf9 Reordered functions; added range. diff -r f3a0c40b75a1 -r 4de15deb3588 lib/builtins.py --- a/lib/builtins.py Sun Oct 22 02:58:06 2006 +0200 +++ b/lib/builtins.py Mon Oct 23 23:59:23 2006 +0200 @@ -743,6 +743,25 @@ class undefined: pass +class xrange: + def __init__(self, start, end, step=1): + self.start = start + self.end = end + self.step = step + self.current = start + + def __iter__(self): + return self + + def next(self): + if self.current >= self.end: + raise StopIteration + current = self.current + self.current += self.step + return current + +# General functions. + def isinstance(obj, cls): return boolean() @@ -759,26 +778,29 @@ max_so_far = i return max_so_far +def range(start, end, step=None): + if start == end: + return [] + elif start > end: + step = step or 1 + i = start + result = [] + while i < end: + result.append(i) + i += 1 + return result + else: + step = step or -1 + i = start + result = [] + while i > end: + result.append(i) + i -= 1 + return result + def str(x): return x.__str__() -class xrange: - def __init__(self, start, end, step=1): - self.start = start - self.end = end - self.step = step - self.current = start - - def __iter__(self): - return self - - def next(self): - if self.current >= self.end: - raise StopIteration - current = self.current - self.current += self.step - return current - # Special values. None of these definitions should be generated by the compiler. # All such definitions should be made in the underlying implementation.