渲染zh-Hant

mori

Translation status: 繁體中文 reader-locale proof. Code fences render through the zh-Hant pipeline; prose is canonical Latin.

Raises a fatal error or panic.

Syntax: mori <expression>

Category#

errors

Examples#

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

Conditional fatal abort with si guard.

# =============================================================================
# mori — Conditional fatal abort with si guard.
# =============================================================================
#
# What this teaches:
#   • fatal abort with `mori` — unconditional and conditional (`si` guard) forms
#   • invariant enforcement — using `mori` with guards to validate function preconditions
#   • the `si` guard is parser sugar for `si cond { mori "msg" }`
#
# Common mistakes:
#   • Using mori for recoverable errors — use iace with a si guard and ⇥ for recoverable failure paths instead.
#
# See also: iace, ergo, si
# =============================================================================

# mori with optional si guard
#
# mori <nuntius> [si <condicio>]
#
# GRAMMAR:
#   abortStmt :← 'mori' expr ['si' expr]
#
# The optional `si` guard is parser sugar:
#   mori "msg" si cond  →  si cond { mori "msg" }
#
# Without the guard, mori 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 mori — unchanged form
    if index < 0 or index  res.longitudo() {
        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.

# =============================================================================
# mori — Raises a fatal error or panic.
# =============================================================================
#
# What this teaches:
#   • fatal unrecoverable abort with `mori` — halts execution with an error message
#   • invariant checking — using `mori` for divisor and bounds checks
#
# Common mistakes:
#   • Using mori for recoverable errors — use iace with ⇥ for recoverable failure paths instead.
#
# See also: iace, ergo
# =============================================================================

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

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

fn accipe(list<int> res, int index)  int {
    # Bounds check with mori
    if index < 0 or index  res.longitudo() {
        panic "index extra fines"
    }
    return res[index]
}

main {
    # Happy path — mori branches not taken
    const _ value  divide(10, 2)
    # 5.0
    print "valor: §"(value)

    # This would call mori:
    # fixum _ malum ← divide(10, 0)

    # Lista accessus
    const _ nums  [1, 2, 3]
    const _ lectum  accipe(nums, 1)
    # 2
    print "valor: §"(lectum)
}