lang/interpret_test/TestAstFunc1/changing-func.txtar
raw| 1 | -- main.mcl -- |
| 2 | # this can return changing functions, and could be optimized, too |
| 3 | func funcgen($b) { |
| 4 | if $b { |
| 5 | func() { |
| 6 | "hello" |
| 7 | } |
| 8 | } else { |
| 9 | func() { |
| 10 | "world" |
| 11 | } |
| 12 | } |
| 13 | } |
| 14 | |
| 15 | $fn1 = funcgen(true) |
| 16 | $fn2 = funcgen(false) |
| 17 | |
| 18 | $out1 = $fn1() |
| 19 | $out2 = $fn2() |
| 20 | |
| 21 | test "${out1}" {} |
| 22 | test "${out2}" {} |
| 23 | -- OUTPUT -- |
| 24 | Edge: FuncValue -> call # fn |
| 25 | Edge: FuncValue -> call # fn |
| 26 | Edge: call -> call # fn |
| 27 | Edge: call -> call # fn |
| 28 | Vertex: FuncValue |
| 29 | Vertex: FuncValue |
| 30 | Vertex: call |
| 31 | Vertex: call |
| 32 | Vertex: call |
| 33 | Vertex: call |
| 34 | Vertex: const |
| 35 | Vertex: const |