रेंडरिंगhi

स्थिर

Translation status: हिन्दी reader-locale proof. Term names and code fences follow the hi pack; supporting prose may still be English.

Declares an immutable binding.

Aliases: const, immutable

Syntax: स्थिर <type|_> <pattern> [← <expression>]

Category#

binding

Examples#

radix/corpus/fixum/fixum.fab (canonical · keyword)#

Declares an immutable binding.

# =============================================================================
# स्थिर — Declares an immutable binding
# =============================================================================
#
# What this teaches:
#   • Declares an immutable binding.
#   • Related keywords: चर, बैठा, ←
#
# Common mistakes:
#   • Reassigning a `स्थिर` binding after initialization — `स्थिर` is immutable; use `चर` for mutable bindings (SEM020) or defer init with a single later assignment.
#
# See also: चर, बैठा, ←
# =============================================================================

# स्थिर — immutable bindings
#
# Immediate init:
#   स्थिर संख्या count ← 0
#   स्थिर _ नाम ← "Marcus"
#
# Deferred init (write-once): declare without ←, assign exactly once later, then
# freeze. The definite-assignment pass rejects reads before that assignment and
# any second assignment.
#   स्थिर संख्या pending
#   pending ← 42
#
# `बैठा x` is sugar for `स्थिर _ x` in both immediate and deferred shapes; see
# बैठा/sit.fab for the compact inferred spelling.
#
# GRAMMAR:
#   varDecl := ('स्थिर' | 'चर') typeAnnotation IDENTIFIER ('←' expression)?
#
# EXPECTED OUTPUT:
#   fixum.expected (Salve, Marcus! / 7 / 30 / 300)

fn scale(bool compact, int base) → int {
    const int factor
    if compact {
        factor ← 10
    }
    else {
        factor ← 100
    }
    return base * factor
}

test "fixum immediate init" {
    const string नाम ← "Marcus"
    const string salve ← "Salve, §!"(नाम)
    assert नाम ≡ "Marcus"
    assert salve ≡ "Salve, Marcus!"
}

test "fixum deferred init writes once" {
    const int pending
    pending ← 7
    assert pending ≡ 7
}

test "fixum factor selected per branch" {
    assert scale(true, 3) ≡ 30
    assert scale(false, 3) ≡ 300
}

main {
    const string नाम ← "Marcus"
    const string salve ← "Salve, §!"(नाम)
    print salve
    const int pending
    pending ← 7
    print pending
    print scale(true, 3)
    print scale(false, 3)
}

Expected output:

Salve, Marcus!
7
30
300