Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Functions

These Controls define script Functions and their parameters. Definitions use ordinary call syntax.

ControlResult
parameter(name, type)Parameter descriptor
vararg(name, type)Variadic parameter descriptor
function(name, parameters..., body)No value

parameter

Builds a descriptor for a required parameter. The name is a literal identifier; the second argument must evaluate to a type description. The descriptor is consumed by function, not stored as a variable value.

vararg

Builds a descriptor for zero or more trailing arguments of the given type. It must be the final parameter descriptor in a Function definition. Inside the body, the parameter name refers to an array of the declared element type. That array is empty when no trailing arguments are supplied.

function

Registers a Function under a literal name. Evaluates parameter descriptors from left to right, captures the current lexical environment, and saves the final argument as the body without evaluating it. The body need not be a block.

function(double, parameter(number, integer), multiply(number, 2))
print(double(21)) / 42

function(sum, vararg(numbers, integer), {
    declare(total, integer, 0)
    for_each(numbers, number, set(total, add(total, number)))
    total
})
print(sum()) / 0
print(sum(1, 2, 3)) / 6

Calls evaluate arguments from left to right. Required parameters receive local bindings, and the body result becomes the Function result. A block returns its final expression; an empty block or a body producing no value yields no value. There is no separate return operation. Returning a descriptor is an error.

Functions capture visible names at definition time, while captured variables remain shared. Later mutations are visible; later declarations are not added to an existing capture. See Function environments and captured names.

declare(offset, integer, 1)
function(adjust, parameter(value, integer), add(value, offset))
set(offset, 5)
print(adjust(10)) / 15

Functions are registered in the runtime’s callable registry, not stored as first-class variable values. A definition inside a block remains callable after the block exits, and retains its captured variables. The caller’s local variables are not automatically visible inside it.

Multiple signatures can share a name when their parameter types distinguish them. Registration rejects overlapping signatures. Wrong parameter descriptors or a misplaced vararg also fail. Duplicate parameter names cause an error when invocation attempts to create the bindings. See overload selection.