THE NOQERI FIELD GUIDE / FUNCTIONS
Give your code room to run.
Ten lessons on reusable functions, typed parameters, generics, composition and clear API design. Learn what runs today and where the compiler's next trails begin.
Noqeri v0.1.4 developer preview. All code snippets use currently documented named functions, parameters and expressions. In-progress callable features are identified in their lessons.
← THE FULL FIELD GUIDE← FINISH BASICS FIRSTFUNCTIONS / 01 OF 10
Functions
Build a reusable move
Declare a function with `function`, list typed parameters inside parentheses, and state its return type after a colon. `return` sends a value back to the caller. Use small functions to make your program easier to follow.
function multiply(a: int, b: int): int {
return a * b
}
function double(value: int): int {
return multiply(value, 2)
}
print(double(10))IMPLEMENTATION NOTE: `function` and explicit `return` are implemented syntax. `export function` exposes a symbol when you need an external entry point.
READ THE SOURCE ↗FUNCTIONS / 02 OF 10
Higher-order functions
Build useful compositions
A higher-order function receives or returns another callable value. General function-value arguments and callbacks are still outside the fully qualified beginner compiler surface. For now, compose named functions directly and make each step explicit.
function addOne(value: int): int {
return value + 1
}
function twiceAdded(value: int): int {
return addOne(addOne(value))
}
print(twiceAdded(10))IMPLEMENTATION NOTE: This executable composition uses supported named calls. General callable values and callback signatures are not presented as verified syntax.
READ THE SOURCE ↗FUNCTIONS / 03 OF 10
Anonymous functions
Closures on the horizon
Anonymous functions create callable values without a module-level name. Capturing surrounding variables also needs a defined ownership and lifetime model. General lambdas and closures remain an ongoing language feature; named helpers are the reliable choice for current programs.
function multiplyByTwo(value: int): int {
return value * 2
}
let answer = multiplyByTwo(21)
print(answer)IMPLEMENTATION NOTE: The example is runnable named-function syntax. Closure-capture semantics are not yet qualified across current compiler backends.
READ THE SOURCE ↗FUNCTIONS / 04 OF 10
Function captures
Make the next call obvious
A capture can stand in for one argument of a function and produce a new callable value. While general capture shorthand is being developed, use a small named function to keep the supplied argument visible.
function add(a: int, b: int): int {
return a + b
}
function addOne(value: int): int {
return add(1, value)
}
print(addOne(10))IMPLEMENTATION NOTE: This helper makes partial application explicit without depending on unsupported placeholder syntax.
READ THE SOURCE ↗FUNCTIONS / 05 OF 10
Generic functions
One function. More than one type.
A generic function uses a type parameter to describe an operation that can work for more than one concrete type. The compiler specializes eligible definitions while still checking the relationship between arguments and return values.
function identity<T>(value: T): T {
return value
}
print(identity(42))
print(identity(true))IMPLEMENTATION NOTE: Generic functions and records are documented. Constraints such as `Ord` and `Numeric` have representative source tests; verify specializations relevant to your target.
READ THE SOURCE ↗FUNCTIONS / 06 OF 10
Pipelines
A clear trail from input to output
A pipeline is a series of transformations. Today, readable Noqeri programs express the stages as ordinary calls or intermediate locals. Writing one named step per operation also makes debugging straightforward.
function double(value: int): int {
return value * 2
}
function addThree(value: int): int {
return value + 3
}
let doubled = double(5)
let result = addThree(doubled)
print(result)IMPLEMENTATION NOTE: The compiler's staged pipeline is an implementation process. A `|>` source expression is not yet part of the verified language guide.
READ THE SOURCE ↗FUNCTIONS / 07 OF 10
Labelled arguments
Let names do the explaining
Labels at call sites can make lengthy argument lists easier to read. Noqeri's documented function calls currently use positional arguments with typed parameter names. Keep parameters descriptive and call them in the declared order.
function calculate(value: int, addend: int, multiplier: int): int {
return value * multiplier + addend
}
print(calculate(2, 3, 4))IMPLEMENTATION NOTE: Named-argument call syntax is not qualified in the current Stage-0 language contract. The documented code uses ordered positional arguments.
READ THE SOURCE ↗FUNCTIONS / 08 OF 10
Label shorthand syntax
Fewer words, same intent
Label shorthand would reuse local variable names when supplying named arguments. Until named calls are supported, clear local names and a normal positional call keep the code easy to audit.
function total(quantity: int, unitPrice: int): int {
return quantity * unitPrice
}
let quantity = 3
let unitPrice = 25
print(total(quantity, unitPrice))IMPLEMENTATION NOTE: The example uses standard locals and function calls; short named-argument call syntax is not a verified feature.
READ THE SOURCE ↗FUNCTIONS / 09 OF 10
Documentation comments
Leave tracks for the next builder
Comments make code easier for your teammates to understand. Noqeri supports `//` source comments. Place concise notes before a function explaining what it expects and returns.
// Compute the area of a rectangular plot.
// width and height are non-negative whole numbers.
function area(width: int, height: int): int {
return width * height
}
print(area(6, 8))IMPLEMENTATION NOTE: The compiler understands these ordinary comments. Specialized doc-comment extraction and generated API documentation are separate tooling features.
READ THE SOURCE ↗FUNCTIONS / 10 OF 10
Deprecations
Retire old paths gracefully
When an API changes, keep a compatibility wrapper where you can and explain which replacement to use. This helps projects migrate gradually without leaving users guessing.
// Preferred helper for new source.
function double(value: int): int {
return value * 2
}
// Legacy name: use double(value) in new code.
function twiceOld(value: int): int {
return double(value)
}
print(twiceOld(5))
print(double(5))IMPLEMENTATION NOTE: The example uses working comments and a wrapper. Automatic compiler deprecation warnings and a `@deprecated` attribute are not claimed as implemented.
READ THE SOURCE ↗Keep running with the pack.
Functions are the foundation of more expressive programs. Explore typed records, collections, control flow and the compiler's development milestones next.
NEXT: FLOW CONTROL ↗EXPLORE THE LANGUAGE ↗GO BEHIND THE COMPILER ↗