Wikipedia: Subroutine
Functions are central in Tengo. They are values that can be assigned to variables, passed as arguments, and returned from other functions.
fmt := import("fmt")
plus := func(a, b) {
return a + b
}
res := plus(1, 2)
fmt.println("1+2 = ", res)
plusPlus := func(a, b, c) {
return a + b + c
}
res = plusPlus(1, 2, 3)
fmt.println("1+2+3 = ", res)
apply := func(f, a, b) {
return f(a, b)
}
fmt.println("apply: ", apply(plus, 5, 3))
try it
1+2 = 3 1+2+3 = 6 apply: 8