Debian Codegraph @

lang/interpret_test/TestAstFunc2/chained-returned-scoped-lambdas.txtar

raw
1 -- main.mcl --
2 $funcgen = func() {
3 func($a) {
4 if $a {
5 func($b) {
6 if $b == "hello" {
7 func() {
8 "hey"
9 }
10 } else {
11 func() {
12 $b
13 }
14 }
15 }
16 } else {
17 func($b) {
18 func() {
19 "wow: " + $b
20 }
21 }
22 }
23 }
24 }
25
26 $fn = $funcgen()
27
28 $fn1 = $fn(true)
29 $fn2 = $fn(false)
30
31 $out1 = $fn1("hello")
32 $out2 = $fn1("there")
33 $out3 = $fn2("hello")
34 $out4 = $fn2("world")
35
36 $name1 = $out1()
37 $name2 = $out2()
38 $name3 = $out3()
39 $name4 = $out4()
40
41 test [$name1,] {} # hey
42 test [$name2,] {} # there
43 test [$name3,] {} # wow: hello
44 test [$name4,] {} # wow: world
45 -- OUTPUT --
46 Vertex: test[hey]
47 Vertex: test[there]
48 Vertex: test[wow: hello]
49 Vertex: test[wow: world]