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:
Lourenço Vales
2025-04-08 14:34:57 +02:00
committed by James Shubin
parent de970ee557
commit ae68dd79cb
3 changed files with 315 additions and 0 deletions

19
examples/lang/range.mcl Normal file
View 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,
}
}