Defining a function
Use thefunc keyword followed by the function name, a parameter list (which may be empty), and a body enclosed in braces:
Calling a function
Use thecall keyword followed by the function name and an argument list (which may be empty):
call looks up the function by name in the current context. If no function with that name has been defined, a UndeclaredFunctionError is raised at runtime.
You must use
call to invoke a function. Writing the function name without call is not valid syntax.A complete example
Function scope
When a function is defined, the runtime creates a freshCoreContext (containing empty variables and functions maps) and attaches it as the function’s scope. When the function is called, its body executes inside that isolated scope.
Function is defined
The
func statement registers the function name in the current context’s functions map and stores the body AST together with a new empty scope.Function is called
The
call statement retrieves the function from the context and runs its body statements using the function’s own scope — not the caller’s scope.Redeclaration error
Defining the same function name twice raises anAlreadyDeclaredFunctionError at runtime:
Current limitations
Parameters are parsed but not bound
Parameters are parsed but not bound
The parser grammar accepts parameters in function definitions and argument expressions in
call statements, but the runner does not currently bind parameter values to names inside the function scope. Defining parameters in the signature is valid syntax but has no effect at runtime.No return values
No return values
Functions do not return values. There is no
return keyword. A function can produce output using print, but cannot pass a computed value back to the caller.No recursion across scopes
No recursion across scopes
Because each function runs in its own isolated scope, calling another function from inside a function requires that function to be present in the inner scope. In the current implementation, functions defined at the top level are not automatically available inside another function’s scope.
Variables
Variable declarations and scope rules.
Imports
Share functions and variables across multiple files.