This adds a for statement which is used to iterate over a list with a body of statements. This is an important data transformation tool which should be used sparingly, but is important to have. An import statement inside of a for loop is not currently supported. We have a simple hack to detect the obvious cases, but more deeply nested scenarios probably won't be caught, and you'll get an obscure error message if you try to do this. This was incredibly challenging to get right, and it's all thanks to Sam for his brilliance. Co-authored-by: Samuel Gélineau <gelisam@gmail.com>
29 lines
569 B
Plaintext
29 lines
569 B
Plaintext
-- main.mcl --
|
|
import "fmt"
|
|
|
|
$list = ["a", "b", "c",]
|
|
|
|
$index = 42 # should be out of scope
|
|
|
|
for $index, $value in $list {
|
|
|
|
class foo($x) {
|
|
$result = func($y1) {
|
|
"hello" + $x + $value + $y1
|
|
}
|
|
}
|
|
include foo($value) as thing
|
|
$result = func($y2) {
|
|
"please" + $y2
|
|
}
|
|
|
|
# XXX: add $thing.some_func and so on... add more tests says sam.
|
|
$s = fmt.printf("%s is %d is %s", $thing.result("!"), $index, $result("!"))
|
|
test [$s,] {}
|
|
}
|
|
|
|
-- OUTPUT --
|
|
Vertex: test[helloaa! is 0 is please!]
|
|
Vertex: test[hellobb! is 1 is please!]
|
|
Vertex: test[hellocc! is 2 is please!]
|