lang: ast, parser: Allow calling anonymous functions

I forgot to plumb this in through the parser. Pretty easy to add,
hopefully I didn't forget any weird corner scope cases here.
This commit is contained in:
James Shubin
2025-01-08 23:06:51 -05:00
parent 1af334f2ce
commit 1538befc93
6 changed files with 138 additions and 2 deletions

View File

@@ -0,0 +1,8 @@
-- main.mcl --
$s = func() {
"hello"
}() # inline lambda call
test [$s,] {}
-- OUTPUT --
Vertex: test[hello]

View File

@@ -0,0 +1,8 @@
-- main.mcl --
$s = func($x) {
"hello" + $x
}("world") # inline lambda call
test [$s,] {}
-- OUTPUT --
Vertex: test[helloworld]

View File

@@ -0,0 +1,10 @@
-- main.mcl --
import "fmt"
$s = fmt.printf("%v", func($x) {
len($x)
}("helloworld")) # inline lambda call
test [$s,] {}
-- OUTPUT --
Vertex: test[10]

View File

@@ -0,0 +1,10 @@
-- main.mcl --
import "fmt"
$s = fmt.printf("%v", func($x) {
len($x)
}(func($x){ $x }("helloworld"))) # inline lambda call as an arg to another
test [$s,] {}
-- OUTPUT --
Vertex: test[10]