Language
Functions
Tea supports named functions, typed parameters, explicit return types, locals, and lambdas.
Functions in Tea are declared with def. Parameters and return types are explicit, which keeps call sites easy to read and makes public APIs predictable.
Named functions
A named function declares its parameters up front, returns a value with return, and closes with end. This is the form you will use for most reusable program logic.
def add(a: Int, b: Int) -> Int
return a + b
end
const total = add(1, 2)
@println(total)Functions can also return early when a branch should stop execution immediately.
def describe(score: Int) -> String
if score >= 90
return "excellent"
end
return "keep going"
endLambdas and closures
Use lambdas for short pieces of behavior you want to pass around or return from another function. They use the |args| => expr form and can capture values from the surrounding scope.
def make_adder(base: Int) -> Func(Int) -> Int
return |value: Int| => base + value
end
const add_two = make_adder(2)
@println(add_two(5))What is stable today
- Named
defdeclarations with typed parameters and returns. returninside functions when you want early exits.Lambdas with
|args| => exprsyntax.Higher-order code via
Func(...) -> ...signatures.