func, and four ways to use it: free functions, instance methods, type functions, and async functions. Every signature is explicit. There is no overload resolution and no hidden receiver.
Free functions
Afunc declared at module scope is a free function.
- Parameters are
name: Typepairs separated by commas. - The return type follows the parameter list after a colon.
- Omitting the return type means the function returns no value.
Instance methods
Afunc declared inside a value, object, or contract is an instance method.
- Value methods have an immutable
thisreceiver. - Object methods have an identity-bearing
thisand may mutatevarmembers. - Contract methods are requirements: no body, just the signature.
Type functions
type func declares a function owned by the type itself, not by any instance. There is no this.
Initialization
init runs once when an object is constructed. It cannot return a value and must assign every required immutable member before completing.
init. Values are assembled with a field block (see construction reference).
Async functions
Async functions declare that they may suspend. Theasync keyword is part of the signature so callers can see suspension might happen.
awaitis only valid insideasync func.awaitwaits for the awaited call; it does not unwrapResult.- Standalone task spawning and cancellation are deferred.
Return statements
return exits the current function, optionally with a value. The value must be assignment-compatible with the declared return type.
Calling functions
- Positional arguments for free functions and instance methods.
- Named arguments are required for object construction (see construction).
- No default parameter values in v0.1.
- No overload resolution: each function name is unique in its scope.
Next steps
Control flow
if, match, and how bindings interact with branching.Functions reference
Complete spec-style reference for every callable form.
