Files
mgmt/lang/interpret_test/TestAstFunc2/stmtforkv24.txtar
James Shubin 2899bc234a lang: Add a forkv loop statement for iterating over a map
This adds a forkv statement which is used to iterate over a map 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 forkv 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.

Note, I couldn't think of a better keyword that "forkv" but suggestions
are welcome if you think you have a better idea. Other ideas were formap
and foreach, but neither got me very excited.
2025-03-08 17:45:29 -05:00

18 lines
180 B
Plaintext

-- main.mcl --
import "fmt"
$map = {0 => "a",}
forkv $key, $val in $map {
$fn = func() {
"hello " + $val
}
$s = $fn()
test [$s,] {}
}
-- OUTPUT --
Vertex: test[hello a]