Renderingen-US

Experimental through version 1. Version 0 was alpha. This is the first language release: the interface is relatively stable, not frozen. Nothing is promised stable until version 2.

intervallum

Translation status: English reader-locale proof. Term names and code fences follow the en pack; supporting prose may still be English.

A stored stepped interval carries its step in its type: length() counts on-step members and contains(v) is true only for on-step values.

Syntax:

Category#

range

Examples#

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

Interval algebra: intersection, union, and span count.

# =============================================================================
# range — Interval algebra: intersection, union, and span count
# =============================================================================
#
# What this teaches:
#   • Interval algebra: intersection, union, and span count.
#   • Related keywords: intersect, union, longitudo, none
#
# 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, none
# =============================================================================

# range — range algebra (intersect, union, longitudo)
#
# `intersect` / `union` return `range<int> ∪ none` (none when disjoint
# or non-adjacent). `longitudo` returns discrete bound-count for int v1.
#
# EXPECTED OUTPUT:
#   none — stdout not pinned for this exemplum.

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

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

Clamp, materialize, and contain via conversion and continet.

# =============================================================================
# range — Clamp, materialize, and contain via conversion and continet
# =============================================================================
#
# What this teaches:
#   • Clamp, materialize, and contain via conversion and continet.
#   • Related keywords: ∈, ↦, list
#
# Common mistakes:
#   • Confusing `‥` (exclusive end) with `…` (inclusive end) — `15 ↦ 0‥10` clamps to 9, while `15 ↦ 0…10` clamps to 10.
#
# See also: ∈, ↦, list
# =============================================================================

# range — conversion clamp, materialize, and continet
#
# Value clamp result type is bound `int` (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) ---
    let int half ← 15 ↦ 0 ‥ 10
    let int closed ← 15 ↦ 0 … 10
    assert half ≡ 9
    assert closed ≡ 10

    # --- materialize to list or 1-d tensor ---
    let list<int> half_list ← 0 ‥ 10 ↦ list<int>
    let list<int> closed_list ← 0 … 3 ↦ list<int>
    let tensor<int, [10]> half_grid ← 0 ‥ 10 ↦ tensor<int, [10]>
    let tensor<int, [4]> closed_grid ← 0 … 3 ↦ tensor<int, [4]>
    let list<int> half_flat ← half_grid.flatten()
    let 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 ---
    let range<int> wide ← 0 ‥ 100
    let range<int> narrow ← wide ↦ 10 … 50
    assert narrow.length() ≡ 41

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

radix/corpus/reference/type/intervallum/range-of-value.fab (canonical · type)#

Walk an range value with for range: the stored interval is the walk.

# =============================================================================
# range — Walk an range value with `for range`
# =============================================================================
#
# What this teaches:
#   • A `for range` source may be a value whose type is `range<int>`,
#     not only a literal `lo‥hi` range expression.
#   • The stored interval is materialized and walked in order: `2‥5` yields
#     `2, 3, 4` (exclusive end) and `2…5` yields `2, 3, 4, 5` (inclusive end).
#   • The loop binding is declared with `let`, and `print` is a statement.
#
# Common mistakes:
#   • Confusing `‥` (exclusive end) with `…` (inclusive end) — `2‥5` is [2,5), `2…5` is [2,5]; the wrong boundary operator changes the walk.
#   • Writing the binding inside `for range r let i` with a type slot — loop binders take no slot.
#
# See also: for range, ‥, …, range
# =============================================================================

# for range over an range value
#
# WHY: pins the C3 `for range` row over a stored interval instead of a literal
# range expression. Both boundary operators walk, in ascending order.
#
# EXPECTED OUTPUT:
#   range-of-value.expected — one value per print, in walk order.

main {
    let range<int> r ← 2 ‥ 5
    for range r let i {
        print i
    }
    let range<int> inclusive ← 2 … 5
    for range inclusive let j {
        print j
    }
}

Expected output:

2
3
4
2
3
4
5

radix/corpus/reference/type/intervallum/stepped-value.fab (canonical · type)#

A stored stepped interval carries its step in its type: length() counts on-step members and contains(v) is true only for on-step values.

# =============================================================================
# range — a stored stepped range carries its step
# =============================================================================
#
# What this teaches:
#   • The step of `0…10 step 2` lives in the value's type: `range<int, 2>`.
#   • `length()` counts the members the step produces: `0…10 step 2` has 6.
#   • `contains(v)` is true only for members on the step: 4 yes, 3 no.
#
# Common mistakes:
#   • Counting the raw span (`0…10` is 11) instead of the stepped member count.
#   • Expecting `contains(3)` to be true because 3 lies between the bounds;
#     membership follows the step, not the span.
#
# See also: length, contains, step, range
# =============================================================================

main {
    # a stored range carries its step in its type
    let range<int, 2> evens ← 0 … 10 step 2
    print evens.length()
    print evens.contains(4)
    print evens.contains(3)
}

Expected output:

6
true
false

radix/corpus/reference/reject/intervallum/arity-reject.fab (supporting · reject)#

The range type takes one bound and at most one step, never three parameters.

# The range type accepts one bound type and at most one step type. Writing a
# third type argument is refused rather than silently dropped, because the
# extra argument has no position the range type could store it in.
#
# DELIBERATE: the declaration below is the rejected form, kept on purpose to
# pin SEM008 intervallum_arity. The accepted spelling is range<int, 2>.

main {
    let range<int, 2, 3> bad ← 0‥10
}

Expected: compilation rejects this example.

radix/corpus/reference/reject/intervallum/bound-reject.fab (supporting · reject)#

A range bound must be a numeric type: text bounds are refused.

# A range walks numeric bounds, so its bound type parameter must be a numeric
# type. A text bound has no ordered walk to offer, so the type is refused
# instead of being lowered to a value the targets cannot step.
#
# DELIBERATE: the declaration below is the rejected form, kept on purpose to
# pin SEM008 intervallum_bound. The accepted spelling is range<int>.

main {
    let range<string> bad ← 0‥10
}

Expected: compilation rejects this example.

radix/corpus/reference/reject/intervallum/la-spelling-reject.fab (supporting · reject)#

The Latin type word range in an en file is a wrong-locale error (expect parse error).

# =============================================================================
# range — Latin range type word in an en file (expect parse error).
# =============================================================================
#
# What this teaches:
#   • Locale surfaces are sealed — the en spelling of the range type is `range`, so the Latin `intervallum` is refused in an en file
#   • Parse error — `PARSE040:wrong_locale_type` names the word written and the en spelling to use instead
#
# Common mistakes:
#   • writing `range<int>` in an en file — write `range<int>`
#
# See also: range
# =============================================================================

# Latin range type word in an en file (expect parse error)
#
# WHY: en and la spellings never mix in one file; the en pack owns `range`.
#
# DELIBERATE: this exemplum keeps the Latin spelling (`range`) on purpose,
# to pin the PARSE040 `wrong_locale_type` diagnostic for the range type.

main {
    let range<int> r ← 1 ‥ 3
    print r
}

Expected: compilation rejects this example.