for
Translation status: English reader-locale proof. Term names and code fences follow the en pack; supporting prose may still be English.
Range iteration is exact at the i64 edge; the step contract is checked at run time and a zero or negative step aborts.
Aliases: iterate
Syntax: for range <start>…<end> step <step> let <item> { <body> }
Category#
loop
Related#
Examples#
radix/corpus/reference/keyword/itera/cursor-iteratio.fab (canonical · keyword)#
Starts a for-each iteration statement.
# =============================================================================
# for — Starts a for-each iteration statement.
# =============================================================================
#
# What this teaches:
# • for-each iteration using stream functions — consumes values yielded via
# `yield` from `generator` and `async_generator` functions
# • sync and async stream modes — `generator` and `async_generator` function signatures
#
# Common mistakes:
# • Forgetting that stream functions must use `generator` or `async_generator` and yield
# values with `yield`.
#
# See also: from, ref, range
# =============================================================================
# for from — cursor function return iteration
#
# for from <cursor-call> let <item> { <body> }
#
# GRAMMAR:
# forInStmt :← 'for' 'from' callExpr 'let' ident block
# cursorDecl :← funcDecl 'generator' | funcDecl 'async_generator'
#
# EXPECTED OUTPUT:
# Sync cursor values and collected list of doubled results.
#
# BACKEND:
# Rust lowers `async_generator` through the async-cursor carrier. Go supports the
# `generator` half and reports `async_generator` as an explicit target gap.
# Multi-value sync stream function that yields values via yield
fn grena(int n) generator → int {
for range 0 ‥ n let i {
yield i
}
}
# Multi-value async stream function that yields values via yield
fn grena_futurum(int n) async_generator → int {
for range 0 ‥ n let i {
yield i
}
}
async_main {
# Direct consumption of cursor yield stream
print "Sync cursor iteration:"
for from grena(3) let n {
print " numerus: §"(n)
}
# Collect all results from cursor function
mut list<int> effecta ← []
for from grena(5) let n {
effecta.append(n * 2)
}
print "Sync collected:"
print effecta
print "Async cursor iteration:"
for from grena_futurum(3) let n {
print " async numerus: §"(n)
}
}Expected output:
Sync cursor iteration:
numerus: 0
numerus: 1
numerus: 2
Sync collected:
[0, 2, 4, 6, 8]
Async cursor iteration:
async numerus: 0
async numerus: 1
async numerus: 2
radix/corpus/reference/keyword/itera/in-functione.fab (canonical · keyword)#
Starts a for-each iteration statement.
# =============================================================================
# for — Starts a for-each iteration statement.
# =============================================================================
#
# What this teaches:
# • accumulator patterns inside functions — using `for from` to compute sums, max, and counts
# • combining iteration with conditional logic (`if`) inside the loop body
#
# Common mistakes:
# • Using the wrong iteration keyword — from for values, ref for indices/keys, range for ranges; mixing them up produces unexpected results.
#
# See also: from, ref, range
# =============================================================================
# for from — accumulator pattern inside fn
#
# for from <list> let <item> { <body> }
#
# GRAMMAR:
# forInStmt :← 'for' 'from' expr 'let' ident block
#
# EXPECTED OUTPUT:
# Sums, max, and counts above a threshold for sample listas.
fn sum(list<int> numeri) → int {
mut int total ← 0
for from numeri let n {
total ← total + n
}
return total
}
# Assumes non-empty list (seed from first element)
fn maximum(list<int> numeri) → int {
mut int max ← numeri[0]
for from numeri let n {
if n ≻ max {
max ← n
}
}
return max
}
fn supra(list<int> numeri, int limen) → int {
mut int int ← 0
for from numeri let n {
if n ≻ limen {
int ← int + 1
}
}
return int
}
main {
let _ numeri ← [1, 2, 3, 4, 5]
print sum(numeri)
print maximum(numeri)
print supra(numeri, 3)
print sum([10, 20, 30])
print maximum([5, 12, 8, 20, 3])
}Expected output:
15
5
2
60
20
radix/corpus/reference/keyword/itera/intervallum-gradus.fab (canonical · keyword)#
Starts a for-each iteration statement.
# =============================================================================
# for — Starts a for-each iteration statement.
# =============================================================================
#
# What this teaches:
# • range iteration with a step value using `step` — controls stride between elements
# • descending ranges: the step is a positive stride, the bounds pick the direction
# • exclusive (`‥`) vs inclusive (`…`) range bounds with step
#
# Common mistakes:
# • Using a step value that never reaches the end bound — the step is always a positive stride (zero or negative is an error); the bounds alone decide whether the range counts up or down.
#
# See also: from, ref, range
# =============================================================================
# for range — ranges with step using per
#
# for range <start>‥<end> per <step> let <item> { <body> }
# for range <start>…<end> per <step> let <item> { <body> }
#
# GRAMMAR:
# forRangeStmt :← 'for' 'range' rangeExpr 'per' expr ('let' | 'mut') ident block
#
# EXPECTED OUTPUT:
# intervallum-gradus.expected — positive-step, inclusive, and descending
# range values pinned from runner stdout.
main {
# Step by 2 (exclusive: 0, 2, 4, 6, 8)
for range 0 ‥ 10 step 2 let i {
print i
}
# Step by 2 (inclusive: 0, 2, 4, 6, 8, 10)
for range 0 … 10 step 2 let i {
print i
}
# Step by 3
for range 0 ‥ 15 step 3 let i {
print i
}
# Descending: the bounds pick the direction, the step stays positive
for range 10 ‥ 0 step 1 let i {
print i
}
# Descending by 2
for range 10 ‥ 0 step 2 let i {
print i
}
}Expected output:
0
2
4
6
8
0
2
4
6
8
10
0
3
6
9
12
10
9
8
7
6
5
4
3
2
1
10
8
6
4
2
radix/corpus/reference/keyword/itera/intervallum.fab (canonical · keyword)#
Starts a for-each iteration statement.
# =============================================================================
# for — Starts a for-each iteration statement.
# =============================================================================
#
# What this teaches:
# • range expressions with exclusive (`‥`) and inclusive (`…`) bounds
# • the explicit `before` keyword for readability in exclusive ranges
# • descending direction in range iteration
#
# Common mistakes:
# • Confusing ‥ (exclusive upper bound) with … (inclusive upper bound) — off-by-one errors are the most common range bug.
#
# See also: from, ref, range
# =============================================================================
# for range — range expressions with exclusive and inclusive bounds
#
# for range <start>‥<end> let <item> { <body> } — exclusive end
# for range <start> before <end> let <item> { <body> } — explicit exclusive
# for range <start>…<end> let <item> { <body> } — inclusive end
#
# GRAMMAR:
# forRangeStmt :← 'for' 'range' rangeExpr ('let' | 'mut') ident block
#
# EXPECTED OUTPUT:
# intervallum.expected — exclusive, ante-exclusive, inclusive, non-zero,
# and descending range values pinned from runner stdout.
main {
# Basic range (exclusive: 0, 1, 2, 3, 4)
for range 0 ‥ 5 let i {
print i
}
# Explicit exclusive with before (same as ‥)
for range 0 ‥ 5 let i {
print i
}
# Inclusive range with … (0, 1, 2, 3, 4, 5)
for range 0 … 5 let i {
print i
}
# Range starting from non-zero
for range 5 ‥ 10 let i {
print i
}
# Descending direction
for range 5 ‥ 0 let i {
print i
}
}Expected output:
0
1
2
3
4
0
1
2
3
4
0
1
2
3
4
5
5
6
7
8
9
5
4
3
2
1
radix/corpus/reference/keyword/itera/lockstep-n2.fab (canonical · keyword)#
Lockstep walk of two lists with two binders.
# =============================================================================
# lockstep N=2 — one walk over two aligned lists.
# =============================================================================
#
# What this teaches:
# • `for from` with a comma-separated source series walks N collections in
# lockstep — one iteration per aligned index, no hand-written counter
# • the binder series names one binder per source, in the same order
# • equal lengths are a law: statically known lengths must already match at
# check; dynamic lengths are guarded before the walk (fail-closed, never
# truncated to the shorter list)
#
# Common mistakes:
# • writing `xs[i]` with `for range` to keep two lists aligned — the
# lockstep series exists exactly for that index-free shape
# • expecting silent truncation on unequal lists — the walk fails closed
#
# See also: from, at
# =============================================================================
main {
let list<string> labels ← ["one", "two", "three"]
let list<int> values ← [1, 2, 3]
for from labels and values let label and value {
print label
print value
}
let list<int> left ← [10, 20, 30]
let list<int> right ← [1, 2, 3]
for from left and right let a and b {
print a - b
}
}Expected output:
one
1
two
2
three
3
9
18
27
radix/corpus/reference/keyword/itera/lockstep-n3.fab (canonical · keyword)#
Lockstep walk of three lists with three binders.
# =============================================================================
# lockstep N=3 — one walk over three aligned lists.
# =============================================================================
#
# What this teaches:
# • the source series takes any N — three collections walk in lockstep with
# three binders, replacing a `for range` loop whose only job was keeping
# three index-aligned lists together
#
# Common mistakes:
# • nesting pair walks for three lists — the series is flat: one clause,
# N sources, N binders
#
# See also: from, at
# =============================================================================
main {
let list<int> bases ← [100, 200, 300]
let list<int> keys ← [1, 2, 3]
let list<int> payloads ← [10, 20, 30]
for from bases and keys and payloads let base and key and payload {
let int total ← base + key + payload
print total
}
let list<int> rows ← [1, 2]
let list<int> cols ← [3, 4]
let list<int> cells ← [5, 6]
for from rows and cols and cells let row and col and cell {
let int grid ← row * col + cell
print grid
}
}Expected output:
111
222
333
8
14
radix/corpus/reference/keyword/itera/nidificatus.fab (canonical · keyword)#
Starts a for-each iteration statement.
# =============================================================================
# for — Starts a for-each iteration statement.
# =============================================================================
#
# What this teaches:
# • nested iteration — combining `for from` and `for range` loops for Cartesian products
# • multiplication tables and coordinate grids as practical examples
#
# Common mistakes:
# • Using range (range iteration) when from or ref is needed for a collection — each nested for must independently choose the correct mode.
#
# See also: from, ref, range
# =============================================================================
# for from — nested loops (Cartesian product)
#
# for from <collection> let <item> { <body> }
# for range <start>‥<end> let <item> { <body> }
#
# GRAMMAR:
# forInStmt :← 'for' 'from' expr 'let' ident block
# forRangeStmt :← 'for' 'range' rangeExpr 'let' ident block
#
# EXPECTED OUTPUT:
# none — row/col pairs, multiplication table, coordinate grids.
#
# BACKEND:
# Go backend does not emit nested for yet — compile-only smoke.
main {
# Nested list iteration — 3 × 3 combinations
let list<int, size 3> rows ← [1, 2, 3]
let list<string, size 3> cols ← ["A", "B", "C"]
for from rows let row {
for from cols let col {
print row, col
}
}
# Multiplication table over exclusive ranges 1‥4 (i, j ∈ {1,2,3})
for range 1 ‥ 4 let i {
for range 1 ‥ 4 let j {
print i, "*", j, "←", i * j
}
}
# Nested ranges: 4 × 4 grid of (x, y) with x, y ∈ {0,1,2,3}
for range 0 ‥ 3 let x {
for range 0 ‥ 3 let y {
print x, y
}
}
}Expected output:
1 A
1 B
1 C
2 A
2 B
2 C
3 A
3 B
3 C
1 * 1 ← 1
1 * 2 ← 2
1 * 3 ← 3
2 * 1 ← 2
2 * 2 ← 4
2 * 3 ← 6
3 * 1 ← 3
3 * 2 ← 6
3 * 3 ← 9
0 0
0 1
0 2
1 0
1 1
1 2
2 0
2 1
2 2
radix/corpus/reference/keyword/itera/range-product-n2.fab (canonical · keyword)#
Nested walk of two numeric ranges with one binder per loop.
# =============================================================================
# nested range walk N=2 — two declared numeric domains, one loop per axis.
#
# What this teaches:
# • explicit nesting visits every (i, j) pair exactly once
# • the outer range controls i and the inner range controls j
# • order is structural: each outer value carries the complete inner walk
#
# Common mistakes:
# • expecting the loops to zip — aligned walks are the separate `for from` series
# • compressing nested loops into a comma-separated head, which currently declines
#
# See also: from, at
# =============================================================================
main {
for range 0 ‥ 2 let i {
for range 0 ‥ 2 let j {
print i
print j
}
}
for range 3 ‥ 5 let first {
for range 1 ‥ 3 let second {
print first
print second
}
}
}Expected output:
0
0
0
1
1
0
1
1
3
1
3
2
4
1
4
2
radix/corpus/reference/keyword/itera/range-product-n3.fab (canonical · keyword)#
Nested walk of three numeric ranges with one binder per loop.
# =============================================================================
# nested range walk N=3 — three declared numeric domains, one loop per axis.
#
# What this teaches:
# • explicit nesting visits every (i, j, k) triple
# • i is outermost, k is innermost, and each binder is scoped to its loop
# • each outer pair carries the complete innermost walk
#
# Common mistakes:
# • compressing the loops into a comma-separated head, which currently declines
# • reading the binders as a tuple to destructure — each is a plain name
#
# See also: from, at
# =============================================================================
main {
for range 1 ‥ 3 let i {
for range 2 ‥ 4 let j {
for range 0 ‥ 2 let k {
print i * 100 + j * 10 + k
}
}
}
for range 5 ‥ 7 let first {
for range 1 ‥ 3 let second {
for range 0 ‥ 2 let third {
print first * 100 + second * 10 + third
}
}
}
}Expected output:
120
121
130
131
220
221
230
231
510
511
520
521
610
611
620
621
radix/corpus/reference/keyword/itera/range-product-semantics.fab (canonical · keyword)#
Nested range semantics: sign classes, offsets, and per-axis steps with exclusive/inclusive boundary twins.
# =============================================================================
# nested range semantics — sign, offset, and per-axis steps, end to end.
# =============================================================================
#
# What this teaches:
# • each two-axis walk below is written as explicit nested `for range` loops:
# the outer axis carries a complete ordered inner walk — no axis is
# ever zipped, reordered, or truncated
# • sign classes are not normalized: crossing (-5‥5), negative-to-
# negative (-8‥-3), and positive-to-positive (2‥7) axes all keep their
# declared values, with and without a step
# • a step applies to its own axis only: a stepped outer offset (1‥9 step
# 3) still walks the inner axis completely, and a stepped inner axis
# (0‥10 step 2) never reorders the nested walk
# • boundary twins: each row appears in the exclusive form (`‥`) and the
# inclusive form (`…`); the twin includes the upper endpoint only when
# the progression reaches it — values are never appended or dropped to
# force the endpoint (2…7 step 2 stays 2, 4, 6; -5…5 step 2 gains 5)
#
# Common mistakes:
# • assuming a zero-based axis — offsets (3‥12, -2‥4) keep their declared
# starts and ends on both axes
# • assuming a descending range needs a negative step — the step is a
# positive stride and the bounds pick the direction: 10‥0 step 2 walks
# 10, 8, 6, 4, 2 and includes 0 only in the inclusive twin
#
# See also: from, at
# =============================================================================
main {
# crossing sign class, no step / stepped, exclusive + inclusive twins
for range -5 ‥ 5 let i {
for range 2 ‥ 4 let j {
print i
print j
}
}
for range -5 … 5 let i {
for range 2 … 4 let j {
print i
print j
}
}
for range -5 ‥ 5 step 2 let i {
for range 2 ‥ 4 let j {
print i
print j
}
}
for range -5 … 5 step 2 let i {
for range 2 … 4 let j {
print i
print j
}
}
# negative-to-negative sign class, no step / stepped, twins
for range -8 ‥ -3 let i {
for range 2 ‥ 4 let j {
print i
print j
}
}
for range -8 … -3 let i {
for range 2 … 4 let j {
print i
print j
}
}
for range -8 ‥ -3 step 2 let i {
for range 2 ‥ 4 let j {
print i
print j
}
}
for range -8 … -3 step 2 let i {
for range 2 … 4 let j {
print i
print j
}
}
# positive-to-positive sign class, no step / stepped, twins
for range 2 ‥ 7 let i {
for range 2 ‥ 4 let j {
print i
print j
}
}
for range 2 … 7 let i {
for range 2 … 4 let j {
print i
print j
}
}
for range 2 ‥ 7 step 2 let i {
for range 2 ‥ 4 let j {
print i
print j
}
}
for range 2 … 7 step 2 let i {
for range 2 … 4 let j {
print i
print j
}
}
# offset row — both axes off zero, twins
for range 3 ‥ 12 let i {
for range -2 ‥ 4 let j {
print i
print j
}
}
for range 3 … 12 let i {
for range -2 … 4 let j {
print i
print j
}
}
# stepped offset row — the stepped outer axis stays outer, twins
for range 1 ‥ 9 step 3 let i {
for range -2 ‥ 4 let j {
print i
print j
}
}
for range 1 … 9 step 3 let i {
for range -2 … 4 let j {
print i
print j
}
}
# zero-start step on the inner axis (inner form of 0‥10 step 2), twins
for range 3 ‥ 5 let i {
for range 0 ‥ 10 step 2 let j {
print i
print j
}
}
for range 3 … 5 let i {
for range 0 … 10 step 2 let j {
print i
print j
}
}
# descending outer axis with a positive stride, twins
for range 10 ‥ 0 step 2 let i {
for range 1 ‥ 3 let j {
print i
print j
}
}
for range 10 … 0 step 2 let i {
for range 1 … 3 let j {
print i
print j
}
}
}Expected output:
-5
2
-5
3
-4
2
-4
3
-3
2
-3
3
-2
2
-2
3
-1
2
-1
3
0
2
0
3
1
2
1
3
2
2
2
3
3
2
3
3
4
2
4
3
-5
2
-5
3
-5
4
-4
2
-4
3
-4
4
-3
2
-3
3
-3
4
-2
2
-2
3
-2
4
-1
2
-1
3
-1
4
0
2
0
3
0
4
1
2
1
3
1
4
2
2
2
3
2
4
3
2
3
3
3
4
4
2
4
3
4
4
5
2
5
3
5
4
-5
2
-5
3
-3
2
-3
3
-1
2
-1
3
1
2
1
3
3
2
3
3
-5
2
-5
3
-5
4
-3
2
-3
3
-3
4
-1
2
-1
3
-1
4
1
2
1
3
1
4
3
2
3
3
3
4
5
2
5
3
5
4
-8
2
-8
3
-7
2
-7
3
-6
2
-6
3
-5
2
-5
3
-4
2
-4
3
-8
2
-8
3
-8
4
-7
2
-7
3
-7
4
-6
2
-6
3
-6
4
-5
2
-5
3
-5
4
-4
2
-4
3
-4
4
-3
2
-3
3
-3
4
-8
2
-8
3
-6
2
-6
3
-4
2
-4
3
-8
2
-8
3
-8
4
-6
2
-6
3
-6
4
-4
2
-4
3
-4
4
2
2
2
3
3
2
3
3
4
2
4
3
5
2
5
3
6
2
6
3
2
2
2
3
2
4
3
2
3
3
3
4
4
2
4
3
4
4
5
2
5
3
5
4
6
2
6
3
6
4
7
2
7
3
7
4
2
2
2
3
4
2
4
3
6
2
6
3
2
2
2
3
2
4
4
2
4
3
4
4
6
2
6
3
6
4
3
-2
3
-1
3
0
3
1
3
2
3
3
4
-2
4
-1
4
0
4
1
4
2
4
3
5
-2
5
-1
5
0
5
1
5
2
5
3
6
-2
6
-1
6
0
6
1
6
2
6
3
7
-2
7
-1
7
0
7
1
7
2
7
3
8
-2
8
-1
8
0
8
1
8
2
8
3
9
-2
9
-1
9
0
9
1
9
2
9
3
10
-2
10
-1
10
0
10
1
10
2
10
3
11
-2
11
-1
11
0
11
1
11
2
11
3
3
-2
3
-1
3
0
3
1
3
2
3
3
3
4
4
-2
4
-1
4
0
4
1
4
2
4
3
4
4
5
-2
5
-1
5
0
5
1
5
2
5
3
5
4
6
-2
6
-1
6
0
6
1
6
2
6
3
6
4
7
-2
7
-1
7
0
7
1
7
2
7
3
7
4
8
-2
8
-1
8
0
8
1
8
2
8
3
8
4
9
-2
9
-1
9
0
9
1
9
2
9
3
9
4
10
-2
10
-1
10
0
10
1
10
2
10
3
10
4
11
-2
11
-1
11
0
11
1
11
2
11
3
11
4
12
-2
12
-1
12
0
12
1
12
2
12
3
12
4
1
-2
1
-1
1
0
1
1
1
2
1
3
4
-2
4
-1
4
0
4
1
4
2
4
3
7
-2
7
-1
7
0
7
1
7
2
7
3
1
-2
1
-1
1
0
1
1
1
2
1
3
1
4
4
-2
4
-1
4
0
4
1
4
2
4
3
4
4
7
-2
7
-1
7
0
7
1
7
2
7
3
7
4
3
0
3
2
3
4
3
6
3
8
4
0
4
2
4
4
4
6
4
8
3
0
3
2
3
4
3
6
3
8
3
10
4
0
4
2
4
4
4
6
4
8
4
10
5
0
5
2
5
4
5
6
5
8
5
10
10
1
10
2
8
1
8
2
6
1
6
2
4
1
4
2
2
1
2
2
10
1
10
2
10
3
8
1
8
2
8
3
6
1
6
2
6
3
4
1
4
2
4
3
2
1
2
2
2
3
0
1
0
2
0
3
radix/corpus/reference/keyword/itera/range-until-before.fab (canonical · keyword)#
The four range forms: exclusive ‥, inclusive …, until (inclusive) and before (exclusive); the bounds pick the direction.
# =============================================================================
# for — the four range forms on one runner
# =============================================================================
#
# What this teaches:
# • `a‥b` — the glyph range with an EXCLUSIVE end: `5‥5` is empty and its
# body never runs, `0‥10 step 4` yields 0, 4, 8.
# • `a…b` — the glyph range with an INCLUSIVE end: `5…5` yields 5 once.
# • `a until b` (la `until`) — the word form with an inclusive end:
# `3 until 6` yields 3, 4, 5, 6.
# • `a before b` (la `before`) — the word form with an exclusive end:
# `3 before 6` yields 3, 4, 5.
# • The direction lives in the bounds: the step is always a positive
# stride, so `10…0 step 5` counts down through 10, 5, 0.
# • The loop binder takes no type slot: `for range a‥b let i { }` binds
# each element fresh (a `mut i` binder exists for bodies that rebind).
#
# Common mistakes:
# • Expecting `5‥5` to yield 5 — an exclusive range meets its end
# immediately, so nothing prints.
# • Writing a negative step to count down — the bounds decide up or down,
# the step is only a stride.
#
# See also: from, ref, range
# =============================================================================
# range-until-before — the four end forms, end to end
#
# POLICY:
# `‥` and `before` exclude the end bound; `…` and `until` include it.
# A negative bound is just a start or end like any other: `-2‥2` climbs
# from -2 up to (but not including) 2, and `2…-2 step 2` descends to the
# inclusive -2.
main {
# exclusive glyph form: 5‥5 is empty, so this body never runs
for range 5 ‥ 5 let i {
print "never5"
}
# inclusive glyph form: 5…5 yields 5 once
for range 5 … 5 let i {
print i
}
# inclusive descending with a stride: the bounds pick the direction
for range 10 … 0 step 5 let i {
print i
}
# exclusive ascending with a stride: 0, 4, 8
for range 0 ‥ 10 step 4 let i {
print i
}
# until: the inclusive word form
for range 3 … 6 let i {
print i
}
# before: the exclusive word form
for range 3 ‥ 6 let i {
print i
}
# a negative start with an exclusive end
for range -2 ‥ 2 let i {
print i
}
# an inclusive end below the start, descending by stride
for range 2 … -2 step 2 let i {
print i
}
}Expected output:
5
10
5
0
0
4
8
3
4
5
6
3
4
5
-2
-1
0
1
2
0
-2
radix/corpus/reference/operator-group/itera/range-runtime-step.fab (canonical · operator-group)#
Range iteration is exact at the i64 edge; the step contract is checked at run time and a zero or negative step aborts.
# =============================================================================
# for — range bounds are exact; the step contract lives at run time.
# =============================================================================
#
# What this teaches:
# • Exact intermediates at the i64 edge — the inclusive range
# 9223372036854775800…9223372036854775807 has eight values and the walk
# counts all eight. The bounds are numbers, not 64-bit containers: nothing
# overflows while the loop counts, and the walk prints 8.
# • The step contract is checked at run time — `for range 0‥5 step s` with
# `mut int s ← -2` is not a compile error. The run prints its earlier
# output, then aborts when the loop is entered with
# "range step must be positive"; the program exits non-zero and the body
# never runs.
#
# Common mistakes:
# • Expecting a negative step to walk the range backwards — the bounds pick
# the direction and the step stays a positive stride.
# • Expecting the run-time step to be validated where it is computed — the
# check fires at loop entry, so earlier prints are already on stdout.
# • Expecting the i64-edge walk to wrap — the bounds are exact without any
# arithmetic on the bound values.
#
# See also: intervallum-gradus, numerus-overflow, for
# =============================================================================
# range-runtime-step — exact bounds, run-time step check
#
# POLICY:
# A range bound is exact; the step is a positive stride whose direction
# comes from the bounds. A step that is zero or negative is a run-time
# trap, not a compile error, so it aborts the run at loop entry.
main {
# (a) i64 edge: eight values, counted without overflow.
mut int n ← 0
for range 9223372036854775800 … 9223372036854775807 let i {
n ← n + 1
}
print n
# (b) run-time step: a non-positive step aborts at loop entry.
mut int s ← -2
print "start"
for range 0 ‥ 5 step s let i {
print i
}
}Expected output:
8
start
radix/corpus/reference/reject/itera/apud-decline.fab (supporting · reject)#
at coordinate iteration declines arity mismatch and unindexed iterables with structured issues.
# =============================================================================
# at decline — arity mismatch and unindexed iterables fail closed.
# =============================================================================
#
# Decline rows (reject reason in each comment):
# 1. arity mismatch — `at [i]` over tensor<f32, [2, 3]> binds 1 coordinate
# for rank 2: SEM010 itera_apud_arity_mismatch (expected=2, actual=1);
# partial binding never happens — the statement declines whole
# 2. ragged — `list<list<f32>>` is a list, and a list is rank 1
# (`rows[r]` takes one index): SEM010 itera_apud_arity_mismatch
# (expected=1, actual=2). Changed by D3.1 — it was
# itera_apud_requires_shaped_iterable while lists had no `at` form.
# 3. set — a set has no index to name: SEM010
# itera_apud_requires_indexed_iterable (`at` needs a list, map,
# tensor, or matrix)
# 4. generic dims — `size R, size C` dims are admitted: the loop bounds are
# read from the tensor at run time (an admit row, not a decline; it was a
# MIR-lane decline until loops over run-time extents landed)
#
# Common mistakes:
# • expecting half-bound coordinates on mismatch — arity == rank is a type
# error, never a partial bind
#
# See also: at, for, from, tensor
# =============================================================================
# at reject cases — expected compile failure
#
# WHY: documents the arity and indexed-iterable contracts for coordinate
# iteration. Cases 1–3 must reject under `faber check` with the tokens
# pinned in apud-decline.expected; case 4 is an admit row kept here beside them.
fn arity(tensor<f32, [2, 3]> grid) → void {
for from grid at [i] let cell {
print cell
}
}
fn ragged(list<list<f32>> rows) → void {
for from rows at [r, c] let cell {
print cell
}
}
fn members(set<int> s) → void {
for from s at [i] let member {
print member
}
}
fn generic<size R, size C>(tensor<f32, [R, C]> grid) → void {
for from grid at [r, c] let cell {
print cell
}
}Expected: compilation rejects this example.
radix/corpus/reference/reject/itera/lockstep-decline.fab (supporting · reject)#
Lockstep declines: source/binder arity, at-coordinate cardinality, and statically known unequal lengths fail closed.
# =============================================================================
# lockstep decline — arity, at-cardinality, and static length laws.
# =============================================================================
#
# Decline rows (reject reason in each comment):
# 1. arity — 2 sources carry 1 binder: SEM010
# itera_lockstep_source_binder_arity_mismatch (one binder per source;
# never a partial bind, same family as the at arity rule)
# 2. at-cardinality — `at [i, j]` on a list zip: SEM010
# itera_lockstep_at_coordinate_cardinality (the shared coordinate does
# not grow with N; one clause names the one index)
# 3. static lengths — two inline literals of unequal element count are
# exact witnesses: SEM010 itera_lockstep_length_mismatch (dynamic
# list<T> lengths defer to the MIR walk guard, which aborts before the
# first body visit — pinned in radix-module lower_test, not in this
# checker oracle)
#
# Common mistakes:
# • expecting a partial bind or silent truncation — every count/length law
# here declines the whole statement
#
# See also: from, at
# =============================================================================
# lockstep reject cases — expected compile failure
#
# WHY: documents the source/binder arity law, the one-shared-coordinate law,
# and the fail-closed equal-length admission for the lockstep series.
fn arity(list<int> ks, list<int> vs) → void {
for from ks and vs let k {
print k
}
}
fn cardinality(list<int> ks, list<int> vs) → void {
for from ks and vs at [i, j] let k and v {
print k
}
}
fn lengths() → void {
for from [1, 2, 3] and [4, 5] let k and v {
print k
}
}Expected: compilation rejects this example.
radix/corpus/reference/reject/itera/range-product-decline.fab (supporting · reject)#
Comma-separated loop clauses are currently refused before nested-loop lowering.
# Nested clauses are parsed, but lowering currently declines the entire statement with the named
# `itera_nested_clause_unsupported` diagnostic; separate nested loop statements remain supported.
# Representative source — expected compile failure.
fn nested(int m, int n) → void {
for range 0‥m, range 0‥n let i, j {
print i + j
}
}Expected: compilation rejects this example.