Default arguments
A trailing parameter may declare = expression. A caller can omit it, and every later non-variadic parameter must also have a default. The expression runs at each omitted call in module scope.
Defaults belong to direct declarations. A call through a stored function still requires its exact positional signature.
fn endpoint(host: string, port: int = 8080) -> string {
"$host:$port"
}
fn main() {
println(endpoint("local"))
println(endpoint("local", 9000))
}
Examples use the moon toolchain version shown beside each result.
Output & diagnostics
Expected: local:8080 local:9000
Ctrl/⌘+Enter runs the current lesson.