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.

?.

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

Null-safe member, index, and call access.

Syntax: <expression>?.<name> | <expression>?[<expression>] | <expression>?(<args>)

Category#

optional-chain

Examples#

radix/corpus/operatores/optional-chain.fab (canonical · operator-group)#

Null-safe member, index, and call access.

# =============================================================================
# ?. — Null-safe member, index, and call access.
# =============================================================================
#
# What this teaches:
#   • Optional chaining — `?.` accesses fields only when the receiver is present, returning `none` otherwise.
#   • Index and call safety — `?[ ]` for safe index access, `?( )` for safe call on optional values.
#
# Common mistakes:
#   • Chaining too deeply — each ?. that hits none short-circuits, making debugging harder.
#
# See also: ?., ?[, ?(, vel, optional
# =============================================================================

# operatores/optional-chain — ?. ?[ ?(
#
# GRAMMAR:
#   optionalSuffix :← '?.' IDENTIFIER | '?[' expr ']' | '?(' argumentList ')'
#
# EXPECTED OUTPUT:
#   Roma, Italia, none, none, a, none
#
# BACKEND:
#   Cross-ref optionalis/optionalis.fab for genus-heavy tour.
#   Optional call ?( — syntax in frontmatter; Rust e2e defers to driver optional-chain tests.

class Locus {
    mut string urbs
    mut string regio optional
}

class Civis {
    mut string name
    mut Locus locus optional
}

main {
    let Civis aelia ← Civis { name = "Aelia", locus = Locus { urbs = "Roma", regio = "Italia" } }
    print aelia?.locus?.urbs
    print aelia?.locus?.regio
    let Civis brutus ← Civis { name = "Brutus" }
    print brutus?.locus?.urbs
    print brutus?.locus?.regio
    let list<string, 3> litterae ← ["a", "b", "c"]
    print litterae?[0]
    print litterae?[10]
}

Expected output:

Roma
Italia
none
none
a
none