العرضar

انهر

Translation status: العربية reader-locale proof. Term names and code fences follow the ar pack; supporting prose may still be English.

Raises a fatal error or panic.

Syntax: انهر <expression>

Category#

errors

Examples#

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

Conditional fatal abort with إذا guard.

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

# انهر with optional إذا guard
#
# انهر <nuntius> [إذا <condicio>]
#
# GRAMMAR:
#   abortStmt :← 'انهر' expr ['إذا' expr]
#
# The optional `إذا` guard is parser sugar:
#   انهر "msg" إذا cond  →  إذا cond { انهر "msg" }
#
# Without the guard, انهر 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 انهر — 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.

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

# انهر — fatal unrecoverable abort
#
# انهر <nuntius>
#
# GRAMMAR:
#   abortStmt :← 'انهر' expr
#
# EXPECTED OUTPUT:
#   Happy-path division and قائمة access; انهر paths are commented out.

fn divide(int a, int b) → float {
    # Use انهر 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 انهر
    if index ≺ 0 or index ≥ numeri.length() {
        panic "index extra fines"
    }
    return numeri[index]
}

main {
    # Happy path — انهر branches not taken
    const float value ← divide(10, 2)
    # 5.0
    print "valor: §"(value)

    # This would call انهر:
    # ثابت _ malum ← divide(10, 0)

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