func, instance methods, type func, init, async func, and await, plus local bindings and return.
func
Declares a function.
Syntax
- At module scope,
funcis a free function. - Inside a
value,object, orcontract,funcis an instance method or requirement. - Omitting the return type means the function returns no value.
- No overload resolution: names must be unique in their scope.
- No default parameter values in v0.1.
Instance method
Afunc declared inside a type.
Rules
- Value methods have an immutable
this. - Object methods have an identity-bearing
thisand may mutatevarmembers. - Contract methods are requirements: signature only, no body.
- Extension methods are deferred.
type func
Declares a function owned by the type itself.
Syntax
- Must be declared inside a
valueorobject. - Has no
thisreceiver. - Called through the type name:
TypeName.functionName(...). - Kairo does not use
staticin v0.1.
init
Initializes an object.
Syntax
- Only allowed inside
object. Values have noinit. - Exactly one primary
initper object in v0.1. - Required immutable members must be assigned before
initcompletes. - Cannot return a value.
- Constructor overloading, constructor delegation, and lifecycle hooks are deferred.
async func
Declares a function that may suspend.
Syntax
- May appear on free functions, instance methods,
type func, and contract requirements. - Not allowed on
initor type declarations. - The language shape is frozen for v0.1; the async runtime is deferred.
await
Suspends the current async function until the awaited call completes.
Syntax
- Only valid inside
async func. - Does not unwrap
Result<T, E>. - Does not create hidden detached background work.
- Between suspension points, code runs in program order.
Local bindings
let
- Immutable binding.
- Type inference is supported when the initializer type is obvious.
var
- Mutable binding.
- Local
varrequires an explicit type in v0.1.
this
References the current instance receiver. Only valid inside instance methods and init. Not available in free functions or type func.
return
- Exits the current callable.
- Returned expression must be assignment-compatible with the declared return type.
- Functions with no declared return type must not return a value.
Related
Functions (language guide)
Higher-level guide to callables.
Operators reference
Operators, control flow, and match expressions.
