lang/interpret_test/TestAstFunc2/scoped-lambda.txtar
raw| 1 | -- main.mcl -- |
| 2 | # this can return changing functions, and could be optimized, too |
| 3 | $funcgen = func() { |
| 4 | func($b) { |
| 5 | if $b { |
| 6 | func() { |
| 7 | "hello" |
| 8 | } |
| 9 | } else { |
| 10 | func() { |
| 11 | "world" |
| 12 | } |
| 13 | } |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | $fn = $funcgen() |
| 18 | |
| 19 | $out1 = $fn(true) |
| 20 | $out2 = $fn(false) |
| 21 | |
| 22 | $name1 = $out1() |
| 23 | $name2 = $out2() |
| 24 | |
| 25 | test "${name1}" {} |
| 26 | test "${name2}" {} |
| 27 | -- OUTPUT -- |
| 28 | Vertex: test[hello] |
| 29 | Vertex: test[world] |