lang/interpret_test/TestAstFunc2/changing-scoped-lambda.txtar
raw| 1 | -- main.mcl -- |
| 2 | # this can return changing functions, and could be optimized, too |
| 3 | $funcgen = func($a) { |
| 4 | if $a { |
| 5 | func($b) { |
| 6 | if $b == "hello" { |
| 7 | func() { |
| 8 | "true-true" |
| 9 | } |
| 10 | } else { |
| 11 | func() { |
| 12 | "true-false" |
| 13 | } |
| 14 | } |
| 15 | } |
| 16 | } else { |
| 17 | func($b) { |
| 18 | if $b == "hello" { |
| 19 | func() { |
| 20 | "false-true" |
| 21 | } |
| 22 | } else { |
| 23 | func() { |
| 24 | "false-false" |
| 25 | } |
| 26 | } |
| 27 | } |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | $fn1 = $funcgen(true) |
| 32 | $fn2 = $funcgen(false) |
| 33 | |
| 34 | $out1 = $fn1("hello") |
| 35 | $out2 = $fn1("world") |
| 36 | $out3 = $fn2("hello") |
| 37 | $out4 = $fn2("world") |
| 38 | |
| 39 | $name1 = $out1() |
| 40 | $name2 = $out2() |
| 41 | $name3 = $out3() |
| 42 | $name4 = $out4() |
| 43 | |
| 44 | test "${name1}" {} |
| 45 | test "${name2}" {} |
| 46 | test "${name3}" {} |
| 47 | test "${name4}" {} |
| 48 | -- OUTPUT -- |
| 49 | Vertex: test[true-true] |
| 50 | Vertex: test[true-false] |
| 51 | Vertex: test[false-true] |
| 52 | Vertex: test[false-false] |