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>
17 lines
266 B
Plaintext
17 lines
266 B
Plaintext
-- main.mcl --
|
|
import "fmt"
|
|
|
|
$list = ["a", "b", "c",]
|
|
|
|
$value = "nope" # should be out of scope
|
|
|
|
for $index, $value in $list {
|
|
$s = fmt.printf("%s is %d", $value, $index)
|
|
test [$s,] {}
|
|
}
|
|
|
|
-- OUTPUT --
|
|
Vertex: test[a is 0]
|
|
Vertex: test[b is 1]
|
|
Vertex: test[c is 2]
|