You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The builtin range function (which returns a RangeIterator, a type capable of providing a sequence of numbers from a starting value to an ending value which increments by a certain amount (1, by default).
This construction is nice because it offers a lot of flexibility in creating ranges, and offers a nice function-like interface which is easy to understand (named arguments can even be used for clarity). But necessitating the instantiation of a RangeIterator (and calling that instance's next() method for each iteration of the loop) is pretty wasteful.
Instead, there could be an AST transformation which would transform such a construct into a highly-optimized while-loop instead without the need to construct a RangeIterator, and without the need to call its next() method each time. The range function would still be available if such behavior were desired, but this simple optimization would make it feel better when reaching for a for in range() as opposed to a traditional while-loop with an incrementing integer.
The text was updated successfully, but these errors were encountered:
The builtin
range
function (which returns aRangeIterator
, a type capable of providing a sequence of numbers from a starting value to an ending value which increments by a certain amount (1, by default).This construction is nice because it offers a lot of flexibility in creating ranges, and offers a nice function-like interface which is easy to understand (named arguments can even be used for clarity). But necessitating the instantiation of a
RangeIterator
(and calling that instance'snext()
method for each iteration of the loop) is pretty wasteful.Instead, there could be an AST transformation which would transform such a construct into a highly-optimized
while
-loop instead without the need to construct aRangeIterator
, and without the need to call itsnext()
method each time. Therange
function would still be available if such behavior were desired, but this simple optimization would make it feel better when reaching for afor in range()
as opposed to a traditionalwhile
-loop with an incrementing integer.The text was updated successfully, but these errors were encountered: