New Feature Request - Range magic(intrinsic) compiler function
https://quality.embarcadero.com/browse/RSP-13804

Hey guys,

Since Delphi does not provide a step statement in for loops, a good way to work around this is by using a Python's range(https://docs.python.org/3/library/functions.html#func-range)-like compiler magic function.
The compiler is already able to generate enumerable instances magically as it does when we use foreach thus I think implementing

Range(Start: Int32; Stop: Int32; Step: Int32): IEnumerable<Int32>

as a intrinsic(magic) function is almost complete and is totally possible in the current compiler state.

Range is also very good for indexing arrays as for loop's to value is inclusive (I mean the foor loop upper bound) is very common use 
for I := 0 to FItems.Length - 1 
With the addition of Range function it could get simplified to 
for I in Range(FItems.Length) thus no subtraction is need.

A Range overload as no parameters would start from 0 with step of 1.

To avoid performance loss is better it get created at compile time as already happens with types that implement GetEnumerator in for in loop.
As for in loop already creates temporary objects and eliminates them when goes out of loop bounds, thus you just need to create the range enumerator (as it uses only integers internally it is not going to leak something) at the compile time that will be returned after the Range call. I think no extra effort is need in the sense of avoiding memory leaks.

Delphi seems to be already prepared to this feature, the only thing is necessary in my humble point of view is the way to create the Range enumerator. This feature is too much valueable as you see users asking for in a lot of post in Delphi and programming blogs.
Shared publiclyView activity