العرضar

فترة

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

Clamp, materialize, and contain via تحويل and continet.

Syntax:

Category#

range

Examples#

radix/corpus/intervallum/algebra.fab (canonical · type)#

Interval algebra: intersection, union, and span count.

# =============================================================================
# فترة — Interval algebra: intersection, union, and span count
# =============================================================================
#
# What this teaches:
#   • Interval algebra: intersection, union, and span count.
#   • Related keywords: intersect, union, longitudo, نوع_لاشيء
#
# Common mistakes:
#   • Confusing `‥` (exclusive end) with `…` (inclusive end) — `0‥6` is [0,6), `0…6` is [0,6]; the wrong boundary operator changes the span.
#
# See also: intersect, union, longitudo, نوع_لاشيء
# =============================================================================

# فترة — range algebra (intersect, union, longitudo)
#
# `intersect` / `union` return `فترة<عدد> ∪ نوع_لاشيء` (نوع_لاشيء when disjoint
# or non-adjacent). `longitudo` returns discrete bound-count for عدد v1.
#
# EXPECTED OUTPUT:
#   none — stdout not pinned for this exemplum.

main {
    const فترة<int> morning ← 0‥6
    const فترة<int> afternoon ← 4‥10
    const فترة<int> overlap ← morning.intersect(afternoon) coalesce 0‥0
    const فترة<int> early ← 0‥5
    const فترة<int> late ← 5‥10
    const فترة<int> workday ← early.union(late) coalesce 0‥0
    const int overlap_span ← overlap.length()
    const int workday_span ← workday.length()
    assert overlap_span ≡ 2
    assert workday_span ≡ 10
    const فترة<int> gap_left ← 0‥3
    const فترة<int> gap_right ← 6‥9
    const فترة<int> ∪ none no_union ← gap_left.union(gap_right)
    assert no_union is none
}

radix/corpus/intervallum/conversio.fab (canonical · type)#

Clamp, materialize, and contain via تحويل and continet.

# =============================================================================
# فترة — Clamp, materialize, and contain via تحويل and continet
# =============================================================================
#
# What this teaches:
#   • Clamp, materialize, and contain via تحويل and continet.
#   • Related keywords: ∈, ↦, قائمة
#
# Common mistakes:
#   • Confusing `‥` (exclusive end) with `…` (inclusive end) — `15 ↦ 0‥10` clamps to 9, while `15 ↦ 0…10` clamps to 10.
#
# See also: ∈, ↦, قائمة
# =============================================================================

# فترة — تحويل clamp, materialize, and continet
#
# Value clamp result type is bound `عدد` (refinement-target special case).
# Range materialize honors declared inclusivity on `‥` / `…`.
#
# EXPECTED OUTPUT:
#   none — stdout not pinned for this exemplum.

main {
    # --- value clamp (half-open interior vs inclusive endpoint) ---
    const int half ← 15 ↦ 0‥10
    const int closed ← 15 ↦ 0…10
    assert half ≡ 9
    assert closed ≡ 10

    # --- materialize to قائمة or 1-d موتر ---
    const list<int> half_list ← 0‥10 ↦ list<int>
    const list<int> closed_list ← 0…3 ↦ list<int>
    const موتر<int, [10]> half_grid ← 0‥10 ↦ موتر<int, [10]>
    const موتر<int, [4]> closed_grid ← 0…3 ↦ موتر<int, [4]>
    const list<int> half_flat ← half_grid.flatten()
    const list<int> closed_flat ← closed_grid.flatten()
    assert half_list.length() ≡ 10
    assert closed_list.length() ≡ 4
    assert half_flat.length() ≡ 10
    assert closed_flat.length() ≡ 4

    # --- range-to-range clamp inherits target inclusivity ---
    const فترة<int> wide ← 0‥100
    const فترة<int> narrow ← wide ↦ 10…50
    assert narrow.length() ≡ 41

    # --- stored containment via continet (`∈` over a range tests the same containment) ---
    const فترة<int> fines ← 0‥10
    const bool inside ← fines.contains(5)
    assert inside
}