lang: core: iter: Add a range function
This commit implements a range function that mimicks python's range built-in by having a start, stop, and range argument. There's also a few examples and tests to mimick Python's examples to guarantee we're consistent with their behaviour.
This commit is contained in:
committed by
James Shubin
parent
de970ee557
commit
ae68dd79cb
19
examples/lang/range.mcl
Normal file
19
examples/lang/range.mcl
Normal file
@@ -0,0 +1,19 @@
|
||||
import "iter"
|
||||
import "fmt"
|
||||
|
||||
print "range" {
|
||||
msg => fmt.printf("%v", iter.range(5)),
|
||||
}
|
||||
|
||||
for $i, $v in iter.range(34, 50) {
|
||||
print [fmt.printf("index is: %d, value is: %d", $i, $v),] {
|
||||
Meta:autogroup => false,
|
||||
}
|
||||
}
|
||||
|
||||
for $i, $v in iter.range(10) {
|
||||
print [fmt.printf("index is: %d", $i),] {
|
||||
msg => fmt.printf("value is: %d", $v),
|
||||
Meta:autogroup => false,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user