Functions
Tython functions are explicit and fully typed.
Declaration
Functions use the func keyword.
Block body:
Expression body:
Core Rules
- Function names must be snake_case.
- Every parameter requires a type annotation.
- Every function requires an explicit return type.
- Function declarations are allowed only at module scope.
- Nested function declarations are rejected.
- Lambdas are not supported.
Parameters and Defaults
Defaults are supported, but required parameters must come first.
Invalid:
Calls
Call forms:
- fully positional:
add(1, 2) - fully named:
greet(name: "Youniss", title: "Dr")
Mixing positional + named is rejected.
Named arguments can appear in any order.
Returns
- Non-
nonefunctions must return a value on every reachable path. nonefunctions may fall off the end.- Use
return nonewhen returning explicitly from anonefunction.
Function Types
Function type syntax is supported in annotations:
Parameter names are part of the function type surface in this phase.