This module offers functionality similar to Python.
There are 4 functions that create iterators with lazy evaluation:
int_iter
: similar to Python'srange()
for integer numbersfloat_iter
: similar to Numpy'sarange
for floatslin_iter
: similar to Numpy'slinspace
log_iter
: similar to Numpy'slogspace
The main defference with the Numpy functions is that the functions in this module return iterators rather than arrays, but can be used to create arrays.
All the iterators have a len
attribute.
for i in int_iter(stop:5) {
println(i)
}
0
1
2
3
4
for i in int_iter(start:3, stop:23, step:4) {
println(i)
}
3
7
11
15
19
for i in int_iter(start:5, stop:-10, step:-3) {
println(i)
}
5
2
-1
-4
-7
for i in float_iter(start:1, stop:3, step:0.5) {
println(i)
}
1.
1.5
2.
2.5
for i in float_iter(stop:-1, step: -0.25) {
println(i)
}
0
-0.25
-0.5
-0.75
for i in lin_iter(start: 0.5, stop: 1.25, len:5) {
println(i)
}
0.5
0.6875
0.875
1.0625
1.25
for i in lin_iter(start: 0.5, stop: 1.25, len:5, endpoint: false) {
println(i)
}
0.5
0.65
0.8
0.95
1.1
for i in log_iter(start: 0, stop: 3, len:5){
println(i)
}
1.
5.623413251903491
31.622776601683796
177.8279410038923
1000
for i in log_iter(start: 0, stop: 3, len:5, base:2){
println(i)
}
1.
1.681792830507429
2.82842712474619
4.756828460010884
8.
r := int_iter(stop:25, step:4)
println('len: $r.len')
len: 7