العرضar

عوض

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

Provides a default when the left side is null.

Aliases: nullish coalescing

Syntax: <expression> عوض <expression>

Category#

logic

Examples#

radix/corpus/vel/vel.fab (canonical · operator-group)#

Provides a default when the left side is null.

test "vel supplies a fallback for nihil" {
    const string ∪ none اسم ← null
    let ostensum ← اسم coalesce "ignotus"
    assert ostensum ≡ "ignotus"
}

test "vel preserves non-nihil values" {
    let nihilum ← 0
    let vacuus ← ""
    let falsus2 ← false
    assert nihilum coalesce 999 ≡ 0
    assert vacuus coalesce "defectum" ≡ ""
    assert falsus2 coalesce true ≡ false
}

test "vel chains to the first non-nihil value" {
    const string ∪ none a ← null
    const string ∪ none b ← null
    const string ∪ none c ← "inventum"
    let primum ← ((a coalesce b) coalesce c) coalesce "nihil"
    assert primum ≡ "inventum"
}
# =============================================================================
# vel — Provides a default when the left side is null.
# =============================================================================
#
# What this teaches:
#   • Nullish coalescing — `vel` supplies a fallback when the left operand is `نوع_لاشيء`
#   • Chaining — multiple `vel` expressions fall through until the first non-`نوع_لاشيء` value
#   • Short-circuit — like `et`/`أو`, the right operand runs only when the left is `نوع_لاشيء`
#
# Common mistakes:
#   • confusing vel (nullish coalescing, checks نوع_لاشيء only) with أو (logical OR), or using vel for تحويل recovery instead of ⇥
#
# See also: نوع_لاشيء
# =============================================================================




# vel — nullish coalescing (not logical OR)
#
# <expr> vel <expr>   -- right side only when left is نوع_لاشيء
#
# GRAMMAR:
#   coalesceExpr :← expr 'vel' expr
#
# EXPECTED OUTPUT:
#   ignotus, Marcus, 0, false, defectum, inventum, 7, supplementum, 9 (vel.expected).

fn fortasse(bool adest) → int ∪ none {
    if adest { return 7 }
    return null
}

fn supplementum(int قيمة) → int {
    print "supplementum"
    return قيمة
}

main {
    # Basic نوع_لاشيء coalescing
    const string ∪ none اسم ← null
    let ostensum ← اسم coalesce "ignotus"
    # "ignotus"
    print ostensum

    # With present value
    const string ∪ none adest ← "Marcus"
    let ostensum2 ← adest coalesce "ignotus"
    # "Marcus"
    print ostensum2

    # Difference from logical أو: vel only checks نوع_لاشيء
    let nihilum ← 0
    let vacuus ← ""
    let falsus2 ← false

    # vel preserves non-nihil values
    # 0
    print nihilum coalesce 999
    # ""
    print vacuus coalesce "defectum"
    # خطأ
    print falsus2 coalesce true
    let alter ← اسم coalesce "defectum"
    print alter

    # Chaining
    const string ∪ none a ← null
    const string ∪ none b ← null
    const string ∪ none c ← "inventum"
    let primum ← ((a coalesce b) coalesce c) coalesce "nihil"
    # "inventum"
    print primum

    # Short-circuit: the fallback runs only when the left side is نوع_لاشيء
    # 7 (no "supplementum" line)
    print fortasse(true) coalesce supplementum(9)
    # "supplementum", then 9
    print fortasse(false) coalesce supplementum(9)
}

Expected output:

ignotus
Marcus
0

falsum
defectum
inventum
7
supplementum
9