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.

let

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

Declares an inferred immutable local.

Syntax: let <name> [← <expression>]

Category#

binding

Examples#

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

Declares an inferred immutable local.

# =============================================================================
# let — Declares an inferred immutable local.
# =============================================================================
#
# What this teaches:
#   • Write-once binding — `let name` declares an inferred-type local that
#     is written once
#   • Supports immediate init (`let _ x ← expr`) and deferred init
#     (`let x` then `x ← expr` later)
#
# Common mistakes:
#   • Confusing `let` with `mut` — `let` creates a write-once binding.
#
# See also: const, mut, ←
# =============================================================================

# let — inferred immutable bindings
#
# Immediate init:
#   let _ name ← expr        -- inferred write-once local
#
# Deferred init:
#   let name               -- deferred: assign once later
#   name ← expr
#
# `let` infers the type; write `let T name ← expr` to state it. `const` is for
# compile-time constants only.
#
# GRAMMAR:
#   sitDecl := 'let' IDENTIFIER ('←' expression)?
#
# EXPECTED OUTPUT:
#   sit.expected

main {
    let _ salve ← "Salve"
    let _ name ← "Marcus"
    let _ nuntius ← "§, §!"(salve, name)
    print nuntius
    let _ label
    label ← "deferred"
    print label
    let _ idem ← nuntius
    print idem
}

Expected output:

Salve, Marcus!
deferred
Salve, Marcus!