Kết xuấtvi

chết

Translation status: Tiếng Việt reader-locale proof. Term names and code fences follow the vi pack; supporting prose may still be English.

Raises a fatal error or panic.

Syntax: chết <expression>

Category#

errors

Examples#

radix/corpus/mori/mori-si-guard.fab (canonical · keyword)#

Conditional fatal abort with nếu guard.

# =============================================================================
# chết — Conditional fatal abort with nếu guard.
# =============================================================================
#
# What this teaches:
#   • fatal abort with `chết` — unconditional and conditional (`nếu` guard) forms
#   • invariant enforcement — using `chết` with guards to validate function preconditions
#   • the `nếu` guard is parser sugar for `nếu cond { chết "msg" }`
#
# Common mistakes:
#   • Using chết for recoverable errors — use ném with a nếu guard and ⇥ for recoverable failure paths instead.
#
# See also: ném, do_đó, nếu
# =============================================================================

# chết with optional nếu guard
#
# chết <nuntius> [nếu <condicio>]
#
# GRAMMAR:
#   abortStmt :← 'chết' expr ['nếu' expr]
#
# The optional `nếu` guard is parser sugar:
#   chết "msg" nếu cond  →  nếu cond { chết "msg" }
#
# Without the guard, chết is unconditional (unchanged).
#
# EXPECTED OUTPUT:
#   "within range"
#   "positive"
#   "not empty"

fn clamp(int x, int min, int max) → int {
    # Guard: abort if min > max — invariant violation
    panic "range inverted" if min ≻ max

    # Guard: abort if value out of range
    panic "value out of range" if x ≺ min or x ≻ max

    return x
}

fn accessus(list<int> res, int index) → int {
    # Unconditional chết — unchanged form
    if index ≺ 0 or index ≥ res.length() {
        panic "index out of bounds"
    }
    return res[index]
}

main {
    # Happy path — guards not triggered
    const int n ← clamp(5, 0, 10)
    print "within range"

    # Happy path — empty list guard not triggered
    const list<int> xs ← [1, 2, 3]
    const int y ← accessus(xs, 1)
    print "positive"

    const list<int> ys ← [42]
    const int z ← accessus(ys, 0)
    print "not empty"
}

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

Raises a fatal error or panic.

# =============================================================================
# chết — Raises a fatal error or panic.
# =============================================================================
#
# What this teaches:
#   • fatal unrecoverable abort with `chết` — halts execution with an error message
#   • invariant checking — using `chết` for divisor and bounds checks
#
# Common mistakes:
#   • Using chết for recoverable errors — use ném with ⇥ for recoverable failure paths instead.
#
# See also: ném, do_đó
# =============================================================================

# chết — fatal unrecoverable abort
#
# chết <nuntius>
#
# GRAMMAR:
#   abortStmt :← 'chết' expr
#
# EXPECTED OUTPUT:
#   Happy-path division and danh_sách access; chết paths are commented out.

fn divide(int a, int b) → float {
    # Use chết for invariant violations
    if b ≡ 0 {
        panic "divisio per nihilum"
    }
    return (a ↦ float) / (b ↦ float)
}

fn accipe(list<int> numeri, int index) → int {
    # Bounds check with chết
    if index ≺ 0 or index ≥ numeri.length() {
        panic "index extra fines"
    }
    return numeri[index]
}

main {
    # Happy path — chết branches not taken
    const float value ← divide(10, 2)
    # 5.0
    print "valor: §"(value)

    # This would call chết:
    # hằng _ malum ← divide(10, 0)

    # Lista accessus
    const list<int> nums ← [1, 2, 3]
    const int lectum ← accipe(nums, 1)
    # 2
    print "valor: §"(lectum)
}