Renderingen-US

Experimental through version 1. Version 0 was alpha. This is the first language release: the interface is relatively stable, not frozen. Nothing is promised stable until version 2.

optional

Translation status: English reader-locale proof. Term names and code fences follow the en pack; supporting prose may still be English.

Marks a named declaration slot (parameter or class field) as voluntary — the caller or provider may omit the value.

Aliases: optional, voluntary

Syntax: <type> <name> optional [= default | coalesce default]

Category#

function

Examples#

radix/corpus/reference/keyword/sponte/sponte.fab (canonical · keyword)#

Marks a named declaration slot (parameter or class field) as voluntary — the caller or provider may omit the value.

# =============================================================================
# optional — Marks a named declaration slot (parameter or class field) as voluntary — the caller or provider may omit the value.
# =============================================================================
#
# What this teaches:
#   • Voluntary parameter syntax — using `optional` to mark function parameters or class fields as optional
#   • Default values — combining `optional` with `vel` to provide fallbacks when the value is omitted
#
# Common mistakes:
#   • confusing optional (optional parameter with a default) with `∪ none` (la `∪ none`, the nullable type) — optional marks omission, `∪ none` marks absence
#
# See also: vel, none, ∪, fn, class
# =============================================================================

# optional — optional parameter / field marker
#
# GRAMMAR:
#   optionalMarker :← 'optional'
#
# EXPECTED OUTPUT:
#   No main — declaration or test-runner surface only.
#
# BACKEND:
#   declaration-only optional slots (whitelist: optional/sponte.fab). Cross-ref: optionalis/optionalis.fab.
#

fn greet(string name, string titulus optional) → string {
    return name
}

fn paginate(int pagina optional coalesce 1) → string {
    return "page"
}

class User {
    mut string name
    mut string email optional
}