| 1 |
-- main.mcl -- |
| 2 |
import "fmt" |
| 3 |
|
| 4 |
$funcgen1 = func($a, $d) { |
| 5 |
func($i) { |
| 6 |
fmt.printf("text: %s, count: %d", $a, $d + $i) |
| 7 |
} |
| 8 |
} |
| 9 |
|
| 10 |
$funcgen2 = func() { |
| 11 |
func($b) { |
| 12 |
if $b == "" { |
| 13 |
$funcgen1("hello magic number", 42) |
| 14 |
} else { |
| 15 |
$funcgen1("hello " + $b, 13) |
| 16 |
} |
| 17 |
} |
| 18 |
} |
| 19 |
|
| 20 |
$some_bool = true |
| 21 |
$fn = if $some_bool { |
| 22 |
$funcgen2() |
| 23 |
} else { |
| 24 |
func($bb) { |
| 25 |
func($ii) { |
| 26 |
if $bb == "james" { |
| 27 |
"hello purpleidea" |
| 28 |
} else { |
| 29 |
if $bb == "" { |
| 30 |
"who is there?" |
| 31 |
} else { |
| 32 |
"hello " + $bb |
| 33 |
} |
| 34 |
} |
| 35 |
} |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
$fn1 = $fn("user") |
| 40 |
$fn2 = $fn("james") |
| 41 |
$fn3 = $fn("") |
| 42 |
|
| 43 |
$out1 = $fn1(1) |
| 44 |
$out2 = $fn2(22) |
| 45 |
$out3 = $fn3(0) |
| 46 |
|
| 47 |
test "${out1}" {} |
| 48 |
test "${out2}" {} |
| 49 |
test "${out3}" {} |
| 50 |
-- OUTPUT -- |
| 51 |
Vertex: test[text: hello james, count: 35] |
| 52 |
Vertex: test[text: hello magic number, count: 42] |
| 53 |
Vertex: test[text: hello user, count: 14] |